eafb1dc6426caa9c9dadf1f64350de27ceb66215
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 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
20 x
="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*}
24 usage: ${0##*/} [-h|--help] [HOST] [DISTRO]
25 Deploy fai config (the one in nfs) to HOST or default faiserver
26 DISTRO is default this distro, or DISTRO for setting up DESKTOP packages.
37 # i use faiserver as a dns alias, but ssh key is associated with
38 # a canonical hostname and we will have ssh warning spam unless we
39 # use it, so look it up just to avoid the warning spam.
40 faiserver_host
=$
(chost
$host) || faiserver_host
=$host
42 rsync
-rlp --delete --relative --exclude /fai
/config
/basefiles
/ fai
/config root@
$faiserver_host:/srv
45 scp
-q ~
/.ssh
/home.pub \
46 root@
$faiserver_host:/srv
/fai
/config
/files
/root
/.ssh
/authorized_keys
/GRUB_PC
47 # todo: automatically disable faiserver after a period so
48 # these files are not exposed.
49 sudo scp
-qr /q
/root
/luks
/q
/root
/shadow \
50 root@
$faiserver_host:/srv
/fai
/config
/distro-install-common
52 # should tar ssh all the files, but these ones really justified it
53 tar -cz /p
/c
/machine_specific
/*/filesystem
/etc
/ssh | \
54 ssh root@
$faiserver_host tar -xz -C /srv
/fai
/config
/distro-install-common
57 .
/a
/bin
/distro-setup
/pkgs
58 pall
+=($
(/a
/bin
/buildscripts
/emacs
-p; /a
/bin
/distro-setup
/distro-pkgs
$distro))
59 { echo PACKAGES
install; echo "${pall[*]}"|
sed 's/ /\n/g'; } | \
60 ssh root@
$faiserver_host dd of
=/srv
/fai
/config
/package_config
/DESKTOP
2>/dev
/null ||
: # broken pipe
63 # built BELENOS basefile with mk-basefile -J BELENOS64. it's stored in
64 # it's own repo which is published alongside this one called
65 # fai-basefiles due to being a large binary file.
68 while read -r sum file; do
70 done < <(cat /a
/bin
/fai-basefiles
/md5sums.txt
)
72 { timeout
2 curl
-s http
://fai-project.org
/download
/basefiles
/md5sums.txt ||
:; } |
73 while read -r sum file; do
74 if [[ ${sums[$file]} && ${sums[$file]} != $sum ]]; then
75 echo "${0##*/}: WARNING!!!!!!!!! NEW UPSTREAM BASEFILE: $file"
78 rsync
-r --delete /a
/bin
/fai-basefiles
/basefiles root@
$faiserver_host:/srv
/fai
/config
79 ssh root@
$faiserver_host bash
<<'EOF'
82 # make it the root because pxe-kexec only looks there.
83 # It wouldn't be too hard to change if we needed.
84 # We could also just dump things in /srv/tftp, but fai
85 # has some defaults, which I don't even use, which expect
86 # the other directory, so it's kind of a tossup, whatever.
87 sed -ri 's,^ *(TFTP_DIRECTORY=).*,\1"/srv/tftp/fai",' /etc/default/tftpd-hpa
88 systemctl restart tftpd-hpa
89 chmod 644 /srv/fai/config/files/root/.ssh/authorized_keys/GRUB_PC
90 chmod -R a+rX /srv/fai/config/distro-install-common
91 # this basefile has tar acls bug, so I'm using my own
93 #cd /srv/fai/config/basefiles
94 #u=http://fai-project.org/download/basefiles/XENIAL64.tar.xz
98 f=/srv/fai/nfsroot/root/.ssh/known_hosts
99 # the known hosts entries that fai already sets up are like
100 # IP,HOSTNAME key_info...
101 # we are skipping the ip, because it doesn't block ssh
102 # with a prompt as long as you have the user supplied hostname,
103 # and i don't want to deal with getting it, it's not adding
104 # any important security in this case.
105 if ! grep -xFq "$line" $f; then
107 printf "%s\n" "$line" >>$f
110 if ! modprobe nfsd &>/dev/null; then
111 # no apt-cache on maru debian, because we are low on space already
112 sed -i '/^ *APTPROXY=/d' /srv/fai/config/class/DEBIAN.var
113 # maru debian doesn't have loopback devs created
114 if ! losetup -f; then
118 if (( ${#x[@]} )); then
119 minor=$(( ${x[-1]#/dev/loop} + 1 ))
121 mknod -m660 /dev/loop$minor b 7 $minor
124 # -B boo only iso, no nfsroot, no paritial miorr, no config space.
125 # -f = force, for overwriting
126 # -S = make squash image for http booting
127 # -d config space url, instead of putting it in the squash.img,
128 # this just makes it so that we don't have to regenerate the img
129 # when the config changes.
131 tar czf /var/www/faiserver/html/config.tar.gz .
132 if $changed || [[ ! -e /var/www/faiserver/html/squash.img ]]; then
133 # note, on maru, selinux needs to be disabled in android before
137 fai-cd -d http://faiserver:8080/config.tar.gz -f -M -S /var/www/faiserver/html/squash.img