2 # Copyright (C) 2016 Ian Kelling
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Initial setup of a fai server on debian. works on localhost.
19 # Set's the current ip as the tftp server. I vaguely remember
20 # that using a hostname does not work
21 # Requires changing dns to point faiserver and running fai-redep
24 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
26 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
28 e
() { echo "$@"; "$@"; }
30 #add-apt-repository -y ppa:fai/ppa
33 wget
-O - http
://fai-project.org
/download
/074BCDE4.asc | apt-key add
-
34 cat >/etc
/apt
/sources.list.d
/fai.list
<<'EOF'
35 deb http://fai-project.org/download jessie koeln
39 # all the dependencies except the dhcp server
40 deps
="$(apt-cache show fai-quickstart | grep ^Depends: |head -n 1|\
41 sed -r 's/^Depends:|,|\|[^,]+|isc-dhcp-server//g')"
44 dpkg
-s $pkg &>/dev
/null
&& continue ||
:
46 echo $pkg >>/etc
/fai
/fai-manually-installed-packages
48 if [[ $to_install ]]; then
49 apt-get
-y install ${to_install[@]}
52 sed="sed -ri --follow-symlinks"
53 $sed 's/^#deb/deb/' /etc
/fai
/apt
/sources.list
54 $sed 's/#LOGUSER/LOGUSER/' /etc
/fai
/fai.conf
55 # from man fai-make-nfsroot,
56 # figured out after partitioning ignored my crypt partition
57 if ! grep cryptsetup
/etc
/fai
/NFSROOT
&>/dev
/null
; then
58 $sed '/^PACKAGES install$/a cryptsetup' /etc
/fai
/NFSROOT
61 { head -n 1 /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts |
awk '{print $1}' \
62 |
tr '\n' ' '; ssh-keyscan localhost |
grep -o "ecdsa-sha2-nistp256.*"; \
63 } >>/srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
65 # this does not alter the config on a new install
66 $sed 's#^([[:space:]]*TFTP_DIRECTORY[[:space:]]*=).*#\1"/srv/tftp"#' \
67 /etc
/default
/tftpd-hpa
69 service tftpd-hpa restart
71 # initially did the basic fai-chboot -Iv $std_arg default
72 # but found in console that it wanted to mount nfsroot
73 # to be the same as my dhcp server.
74 # Figured out to change the root= parameter from googling,
75 # and seeing fai-chboot -L
76 # using hostname failed.
77 # for -f, combined the 2 defaults so it will reboot and print to screen.
79 # Add debug to -f flag for more verbose output.
81 std_arg
="-u nfs://faiserver/srv/fai/config"
82 e fai-chboot
-Iv $std_arg default
# reset so we are idempotent
83 kernel
=$
(fai-chboot
-L '^default$' |
awk '{print $3}')
84 type -t host &>/dev
/null || apt-get
-y install dnsutils
85 # resolve host using gateway address
86 my_ip
=$
(host faiserver $
(route
-n |
sed -rn 's/^(0\.){3}0\s+(\S+).*/\2/p') | \
87 sed -rn 's/^\S+ has address //p')
88 k_args
=$
(fai-chboot
-L '^default$' | \
89 sed -r "s/^(\S+\s+){3}(.*root=)(.*)/\2$my_ip:\3/")
90 e fai-chboot
-k "$k_args" -v -f verbose
,sshd
,createvt
,reboot
$std_arg $kernel default
92 # make the faiserver also the apt proxy server
93 apt-get
-y install apt-cacher-ng
95 # background on choosing apt-cacher-ng:
96 # googling around a bit finds 2 main solutions:
97 # http://askubuntu.com/questions/3503/best-way-to-cache-apt-downloads-on-a-lan
98 # apt-cacher-ng doesn't have zeroconf.
99 # It touts having minimal dependencies, but I don't care.
100 # The downside to squid-deb-proxy is that it's config is for specific repos,
101 # you have to add all the repos you use.
102 # That is the main reason I use apt-cacher-ng.
103 # It has a web portal, at http://faiserver:3142/acng-report.html
106 # random fai note: as far as I can tell, profiles are just for putting
107 # in a selectable boot menu, which I don't want.
109 # the logsave prompted because the hostname faiserver was uknown.
110 # Here it was faiserver.lan when running from a faiserver vm.
111 # When running from a normal host with faiserver alias, it was the normal hosts name.
112 $sed 's/(^[^,]+,)\S+/\1faiserver/' /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
113 # ditch the logo banner up top which screws with less.
114 touch /srv
/fai
/nfsroot
/.nocolorlogo