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