revert chost, broke for localhost
[automated-distro-installer] / fai-redep
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
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.
8
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.
13
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.
17 set -eE -o pipefail
18 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
19
20 x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*}
21
22 usage() {
23 cat <<EOF
24 usage: ${0##*/} [-h|--help]
25 Deploy fai configuration to host "faiserver"
26 EOF
27 exit $1
28 }
29 case $1 in
30 -h|--help) usage ;;
31 esac
32
33
34 # i use faiserver as a dns alias, but ssh key is associated with
35 # a canonical hostname and we will have ssh warning spam unless we
36 # use it, so look it up just to avoid the warning spam.
37 faiserver_host=$(chost faiserver) || faiserver_host=faiserver
38
39 shopt -s extglob
40 ssh root@$faiserver_host rm -rf /srv/fai/config/!(basefiles)
41 scp -qr fai/config root@$faiserver_host:/srv/fai
42
43
44 scp -q ~/.ssh/id_rsa.pub \
45 root@$faiserver_host:/srv/fai/config/files/root/.ssh/authorized_keys/GRUB_PC
46 # todo: automatically disable faiserver after a period so
47 # these files are not exposed.
48 s scp -qr /q/root/luks /q/root/shadow \
49 root@$faiserver_host:/srv/fai/config/distro-install-common
50
51 # should tar ssh all the files, but these ones really justified it
52 tar -cz /p/c/machine_specific/*/filesystem/etc/ssh | \
53 ssh root@$faiserver_host tar -xz -C /srv/fai/config/distro-install-common
54 scp -q /a/bin/fai/devbyid root@$faiserver_host:/srv/fai/nfsroot/usr/local/bin
55
56
57 # built BELANOS basefile with mk-basefile -J BELENOS64. it's stored in
58 # it's own repo which is published alongside this one called
59 # fai-basefiles due to being a large binary file.
60
61 declare -A sums
62 while read -r sum file; do
63 sums[$file]=$sum
64 done < <(cat /a/bin/fai-basefiles/md5sums.txt)
65
66 curl -s http://fai-project.org/download/basefiles/md5sums.txt |
67 while read -r sum file; do
68 if [[ ${sums[$file]} && ${sums[$file]} != $sum ]]; then
69 echo "${0##*/}: WARNING!!!!!!!!! NEW UPSTREAM BASEFILE: $file"
70 fi
71 done
72 scp -q /a/bin/fai-basefiles/*.tar.xz root@$faiserver_host:/srv/fai/config/basefiles
73 ssh root@$faiserver_host bash <<'EOF'
74 set -eE -o pipefail
75 set -x
76 # make it the root because pxe-kexec only looks there.
77 # It wouldn't be too hard to change if we needed.
78 # We could also just dump things in /srv/tftp, but fai
79 # has some defaults, which I don't even use, which expect
80 # the other directory, so it's kind of a tossup, whatever.
81 sed -ri 's,^ *(TFTP_DIRECTORY=).*,\1"/srv/tftp/fai",' /etc/default/tftpd-hpa
82 systemctl restart tftpd-hpa
83 chmod 644 /srv/fai/config/files/root/.ssh/authorized_keys/GRUB_PC
84 chmod -R a+rX /srv/fai/config/distro-install-common
85 # this basefile has tar acls bug, so I'm using my own
86 # local one for now.
87 #cd /srv/fai/config/basefiles
88 #u=http://fai-project.org/download/basefiles/XENIAL64.tar.xz
89 #wget -nv -N $u
90 EOF
91