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 -i 's/^#deb/deb/' /etc
/fai
/apt
/sources.list
38 sed -i 's/#LOGUSER/LOGUSER/' /etc
/fai
/fai.conf
39 # from man fai-make-nfsroot,
40 # figured out after partitioning ignored my crypt partition
41 if ! grep cryptsetup
/etc
/fai
/NFSROOT
&>/dev
/null
; then
42 sed -ri '/^PACKAGES install$/a cryptsetup' /etc
/fai
/NFSROOT
45 { head -n 1 /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts |
awk '{print $1}' \
46 |
tr '\n' ' '; ssh-keyscan localhost |
grep -o "ecdsa-sha2-nistp256.*"; \
47 } >>/srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
49 # this does not alter the config on a new install
50 sed -ri 's#^([[:space:]]*TFTP_DIRECTORY[[:space:]]*=).*#\1"/srv/tftp"#' \
51 /etc
/default
/tftpd-hpa
53 service tftpd-hpa restart
55 # initially did the basic fai-chboot -Iv $std_arg default
56 # but found in console that it wanted to mount nfsroot
57 # to be the same as my dhcp server.
58 # Figured out to change the root= parameter from googling,
59 # and seeing fai-chboot -L
60 # using hostname failed.
61 # for -f, combined the 2 defaults so it will reboot and print to screen.
63 # Add debug to -f flag for more verbose output.
65 std_arg
="-u nfs://faiserver/srv/fai/config"
66 e fai-chboot
-Iv $std_arg default
# reset so we are idempotent
67 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
68 type -t host &>/dev
/null || apt-get
-y install dnsutils
69 # resolve host using gateway address
70 my_ip
=$
(host faiserver $
(route
-n |
sed -rn 's/^(0\.){3}0\s+(\S+).*/\2/p') | \
71 sed -rn 's/^\S+ has address //p')
72 k_args
=$
(fai-chboot
-L '^default$' | \
73 sed -r "s/^(\S+\s+){3}(.*root=)(.*)/\2$my_ip:\3/")
74 e fai-chboot
-k "$k_args" -v -f verbose
,sshd
,createvt
,reboot
$std_arg $kernel default
76 # make the faiserver also the apt proxy server
77 apt-get
-y install apt-cacher-ng
79 # background on choosing apt-cacher-ng:
80 # googling around a bit finds 2 main solutions:
81 # http://askubuntu.com/questions/3503/best-way-to-cache-apt-downloads-on-a-lan
82 # apt-cacher-ng doesn't have zeroconf.
83 # It touts having minimal dependencies, but I don't care.
84 # The downside to squid-deb-proxy is that it's config is for specific repos,
85 # you have to add all the repos you use.
86 # That is the main reason I use apt-cacher-ng.
87 # It has a web portal, at http://faiserver:3142/acng-report.html
90 # random fai note: as far as I can tell, profiles are just for putting
91 # in a selectable boot menu, which I don't want.
93 # the logsave prompted because the hostname faiserver was uknown.
94 # Here it was faiserver.lan when running from a faiserver vm.
95 # When running from a normal host with faiserver alias, it was the normal hosts name.
96 sed -ri 's/(^[^,]+,)\S+/\1faiserver/' /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
97 # ditch the logo banner up top which screws with less.
98 touch /srv
/fai
/nfsroot
/.nocolorlogo