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 # Usage: faiserver-setup
20 # Initial setup of a fai server on debian. works on localhost.
21 # Set's the current ip as the tftp server. I vaguely remember
22 # that using a hostname does not work.
23 # Separate from running this, faiserver needs to be setup in dns
24 # to point to whatever host this is run on.
27 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
29 [[ $EUID == 0 ]] ||
exec sudo
"${BASH_SOURCE}" "$@"
31 e
() { echo "$@"; "$@"; }
33 # When stretch becomes stable, change this to stretch.
34 # I've tested this with stretch, it works, but notably,
35 # the automatic basefile getting will be for stretch
36 # instead of jessie, so if you install jessie, you need
37 # to setup the basefile and it's corresponding class.
39 sed="sed -ri --follow-symlinks"
41 if grep -xFq 'VERSION="9 (stretch)"' /etc
/os-release
; then
42 # if we use stretch, no need for fai-project repo.
43 # this will need to be updated when there is a codename
45 rm -f /etc
/apt
/sources.list.d
/fai.list
47 wget
-O - http
://fai-project.org
/download
/074BCDE4.asc | apt-key add
-
48 cat >/etc
/apt
/sources.list.d
/fai.list
<<'EOF'
49 deb http://fai-project.org/download jessie koeln
54 #add-apt-repository -y ppa:fai/ppa
61 # Relevant packages from fai-quickstart depends and fai-server recommends.
62 # I especially do not wait isc-dhcp-server or an inetd
63 apt-get
install -y fai-doc nfs-kernel-server tftpd-hpa
tar reprepro squashfs-tools binutils
64 apt-get
install --no-install-recommends -y fai-server
66 r
=http
://http.us.debian.org
/debian
67 # like default, but scrap httpredir, and nonfree.
68 # All my systems should be able to get along without nonfree
69 # for a base working system afaik.
70 dd of
=/etc
/fai
/apt
/sources.list
<<EOF
71 deb $r $base main contrib
72 deb http://security.debian.org/debian-security $base/updates main contrib
75 if [[ $base == jessie
]]; then
76 tee -a /etc
/fai
/apt
/sources.list
<<'EOF'
77 # uncommenting this from the defaults. it's got bug fixes.
78 # repository that may contain newer fai packages for jessie
79 deb http://fai-project.org/download jessie koeln
80 # fix tar https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=819978
81 deb http://ftp.debian.org/debian jessie-backports main
84 # note, fai doesn't look at /etc/fai/apt/preferences.d
85 cat >/etc
/fai
/apt
/preferences
<<'EOF'
87 Pin: release a=jessie-backports
93 # tried out a stretch base, doesn't work yet.
94 $sed -f - /etc
/fai
/nfsroot.conf
<<EOF
95 s,^( *FAI_DEBOOTSTRAP=).*,\1"$base $r",
98 $sed 's/#LOGUSER/LOGUSER/' /etc
/fai
/fai.conf
99 # from man fai-make-nfsroot,
100 # figured out after partitioning ignored my crypt partition
103 if ! grep cryptsetup
/etc
/fai
/NFSROOT
&>/dev
/null
; then
104 $sed '/^PACKAGES install$/a cryptsetup' /etc
/fai
/NFSROOT
107 { head -n 1 /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts |
awk '{print $1}' \
108 |
tr '\n' ' '; ssh-keyscan localhost |
grep -o "ecdsa-sha2-nistp256.*"; \
109 } >>/srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
111 # initially did the basic fai-chboot -Iv $std_arg default
112 # but found in console that it wanted to mount nfsroot
113 # to be the same as my dhcp server.
114 # Figured out to change the root= parameter from googling,
115 # and seeing fai-chboot -L
116 # using hostname failed.
117 # for -f, combined the 2 defaults so it will reboot and print to screen.
119 # Add debug to -f flag for more verbose output.
121 # make the faiserver also the apt proxy server
122 apt-get
-y install apt-cacher-ng
124 # background on choosing apt-cacher-ng:
125 # googling around a bit finds 2 main solutions:
126 # http://askubuntu.com/questions/3503/best-way-to-cache-apt-downloads-on-a-lan
127 # apt-cacher-ng doesn't have zeroconf.
128 # It touts having minimal dependencies, but I don't care.
129 # The downside to squid-deb-proxy is that it's config is for specific repos,
130 # you have to add all the repos you use.
131 # That is the main reason I use apt-cacher-ng.
132 # It has a web portal, at http://faiserver:3142/acng-report.html
135 # random fai note: as far as I can tell, profiles are just for putting
136 # in a selectable boot menu, which I don't want.
138 # the logsave prompted because the hostname faiserver was uknown.
139 # Here it was faiserver.lan when running from a faiserver vm.
140 # When running from a normal host with faiserver alias, it was the normal hosts name.
141 $sed 's/(^[^,]+,)\S+/\1faiserver/' /srv
/fai
/nfsroot
/root
/.ssh
/known_hosts
142 # ditch the logo banner up top which screws with less.
143 touch /srv
/fai
/nfsroot
/.nocolorlogo