3 # Initial setup of a fai server on debian. works on localhost.
4 # Set's the current ip as the tftp server. I vaguely remember
5 # that using a hostname does not work
6 # Requires changing dns to point faiserver and running fai-redep
9 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
11 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
13 e
() { echo "$@"; "$@"; }
15 #add-apt-repository -y ppa:fai/ppa
18 wget
-O - http
://fai-project.org
/download
/074BCDE4.asc | apt-key add
-
19 cat >/etc
/apt
/sources.list.d
/fai.list
<<'EOF'
20 deb http://fai-project.org/download jessie koeln
24 # all the dependencies except the dhcp server
25 deps
="$(apt-cache show fai-quickstart | grep ^Depends: |head -n 1|\
26 sed -r 's/^Depends:|,|\|[^,]+|isc-dhcp-server//g')"
29 dpkg
-s $pkg &>/dev
/null
&& continue ||
:
31 echo $pkg >>/etc
/fai
/fai-manually-installed-packages
33 if [[ $to_install ]]; then
34 apt-get
-y install ${to_install[@]}
37 sed="sed -ri --follow-symlinks"
38 $sed 's/^#deb/deb/' /etc
/fai
/apt
/sources.list
39 $sed 's/#LOGUSER/LOGUSER/' /etc
/fai
/fai.conf
40 # from man fai-make-nfsroot,
41 # figured out after partitioning ignored my crypt partition
42 if ! grep cryptsetup
/etc
/fai
/NFSROOT
&>/dev
/null
; then
43 $sed '/^PACKAGES install$/a cryptsetup' /etc
/fai
/NFSROOT
46 { head -n 1 /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts |
awk '{print $1}' \
47 |
tr '\n' ' '; ssh-keyscan localhost |
grep -o "ecdsa-sha2-nistp256.*"; \
48 } >>/srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
50 # this does not alter the config on a new install
51 $sed 's#^([[:space:]]*TFTP_DIRECTORY[[:space:]]*=).*#\1"/srv/tftp"#' \
52 /etc
/default
/tftpd-hpa
54 service tftpd-hpa restart
56 # initially did the basic fai-chboot -Iv $std_arg default
57 # but found in console that it wanted to mount nfsroot
58 # to be the same as my dhcp server.
59 # Figured out to change the root= parameter from googling,
60 # and seeing fai-chboot -L
61 # using hostname failed.
62 # for -f, combined the 2 defaults so it will reboot and print to screen.
64 # Add debug to -f flag for more verbose output.
66 std_arg
="-u nfs://faiserver/srv/fai/config"
67 e fai-chboot
-Iv $std_arg default
# reset so we are idempotent
68 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
69 type -t host &>/dev
/null || apt-get
-y install dnsutils
70 # resolve host using gateway address
71 my_ip
=$
(host faiserver $
(route
-n |
sed -rn 's/^(0\.){3}0\s+(\S+).*/\2/p') | \
72 sed -rn 's/^\S+ has address //p')
73 k_args
=$
(fai-chboot
-L '^default$' | \
74 sed -r "s/^(\S+\s+){3}(.*root=)(.*)/\2$my_ip:\3/")
75 e fai-chboot
-k "$k_args" -v -f verbose
,sshd
,createvt
,reboot
$std_arg $kernel default
77 # make the faiserver also the apt proxy server
78 apt-get
-y install apt-cacher-ng
80 # background on choosing apt-cacher-ng:
81 # googling around a bit finds 2 main solutions:
82 # http://askubuntu.com/questions/3503/best-way-to-cache-apt-downloads-on-a-lan
83 # apt-cacher-ng doesn't have zeroconf.
84 # It touts having minimal dependencies, but I don't care.
85 # The downside to squid-deb-proxy is that it's config is for specific repos,
86 # you have to add all the repos you use.
87 # That is the main reason I use apt-cacher-ng.
88 # It has a web portal, at http://faiserver:3142/acng-report.html
91 # random fai note: as far as I can tell, profiles are just for putting
92 # in a selectable boot menu, which I don't want.
94 # the logsave prompted because the hostname faiserver was uknown.
95 # Here it was faiserver.lan when running from a faiserver vm.
96 # When running from a normal host with faiserver alias, it was the normal hosts name.
97 $sed 's/(^[^,]+,)\S+/\1faiserver/' /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
98 # ditch the logo banner up top which screws with less.
99 touch /srv
/fai
/nfsroot
/.nocolorlogo