3 # initial setup of a fai server on debian
6 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
8 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
11 #add-apt-repository -y ppa:fai/ppa
14 wget
-O - http
://fai-project.org
/download
/074BCDE4.asc | apt-key add
-
15 cat >/etc
/apt
/sources.list.d
/fai.list
<<'EOF'
16 deb http://fai-project.org/download jessie koeln
20 # all the dependencies except the dhcp server
21 apt-get
-y install $
(apt-cache show fai-quickstart |
grep ^Depends
: |
head -n 1|\
22 sed -r 's/^Depends:|,|\|[^,]+|isc-dhcp-server//g')
23 sed -i 's/^#deb/deb/' /etc
/fai
/apt
/sources.list
24 sed -i 's/#LOGUSER/LOGUSER/' /etc
/fai
/fai.conf
25 # from man fai-make-nfsroot,
26 # figured out after partitioning ignored my crypt partition
27 if ! grep cryptsetup
/etc
/fai
/NFSROOT
&>/dev
/null
; then
28 sed -ri '/^PACKAGES install$/a cryptsetup' /etc
/fai
/NFSROOT
31 { head -n 1 /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts |
awk '{print $1}' \
32 |
tr '\n' ' '; ssh-keyscan localhost |
grep -o "ecdsa-sha2-nistp256.*"; \
33 } >>/srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
35 # this does not alter the config on a new install
36 sed -ri 's#^([[:space:]]*TFTP_DIRECTORY[[:space:]]*=).*#\1"/srv/tftp"#' \
37 /etc
/default
/tftpd-hpa
39 service tftpd-hpa restart
41 # initially did the basic fai-chboot -Iv $std_arg default
42 # but found in console that it wanted to mount nfsroot
43 # to be the same as my dhcp server.
44 # Figured out to change the root= parameter from googling,
45 # and seeing fai-chboot -L
46 # using hostname failed.
47 # for -f, combined the 2 defaults so it will reboot and print to screen.
49 # Add debug to -f flag for more verbose output.
51 std_arg
="-u nfs://faiserver/srv/fai/config"
52 fai-chboot
-Iv $std_arg default
53 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
54 type -t host &>/dev
/null || apt-get
-y install dnsutils
55 my_ip
=$
(host faiserver $
(route
-n |
sed -rn 's/^(0\.){3}0\s+(\S+).*/\2/p') | \
56 sed -rn 's/^faiserver has address //p')
57 k_args
=$
(fai-chboot
-L '^default$' | \
58 sed -r "s/^(\S+\s+){3}(.*root=)(.*)/\2$my_ip:\3/")
59 fai-chboot
-k "$k_args" -v -f verbose
,sshd
,createvt
,reboot
$std_arg $kernel default
61 # make the faiserver also the apt proxy server
62 apt-get
-y install apt-cacher-ng
64 # background on choosing apt-cacher-ng:
65 # googling around a bit finds 2 main solutions:
66 # http://askubuntu.com/questions/3503/best-way-to-cache-apt-downloads-on-a-lan
67 # apt-cacher-ng doesn't have zeroconf.
68 # It touts having minimal dependencies, but I don't care.
69 # The downside to squid-deb-proxy is that it's config is for specific repos,
70 # you have to add all the repos you use.
71 # That is the main reason I use apt-cacher-ng.
72 # It has a web portal, at http://faiserver:3142/acng-report.html
75 # random fai note: as far as I can tell, profiles are just for putting
76 # in a selectable boot menu, which I don't want.
78 # somewhere I call it faiserver, but debian's default is faiserver.lan
79 sed -ri 's/faiserver.lan/faiserver/' /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts