various fixes and improvements
[automated-distro-installer] / fai-redep
1 #!/bin/bash -l
2 set -x
3
4 # Deploy fai configuration to faiserver,
5 # then start a virtual machine to test the config.
6
7 set -eE -o pipefail
8 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
9
10 cd $(dirname $(readlink -f "$BASH_SOURCE"))
11
12
13 # i use faiserver as a dns alias, but ssh key is associated with
14 # a canonical hostname and we will have ssh warning spam unless we
15 # use it, so look it up.
16 faiserver_host=$(chost faiserver) || faiserver_host=faiserver
17
18
19 ssh root@$faiserver_host rm -rf /srv/fai/config
20 scp -r fai/config root@$faiserver_host:/srv/fai
21 # fai example pass: fai
22 #ROOTPW='$1$kBnWcO.E$djxB128U7dMkrltJHPf6d1'
23
24 # generating a hashed password:
25 # under debian, you can do
26 # echo "yoursecrectpassword" | mkpasswd -m sha-512 -s
27 # On arch, best seems to be copy your shadow file to a temp location,
28 # then passwd, get out the new pass, then copy the shadow file back.
29
30 f=/q/root/shadow/standard
31 if s test -e $f; then
32 ssh root@$faiserver_host tee -a /srv/fai/config/class/DEFAULT.var <<EOF
33 ROOTPW='$(s cat $f)'
34 EOF
35 fi
36
37 tpvar="$(s cat /q/root/shadow/traci-simple)"
38 ssh root@$faiserver_host tee -a /srv/fai/config/class/tp.var <<EOF
39 ROOTPW='$tpvar'
40 EOF
41
42 scp ~/.ssh/id_rsa.pub \
43 root@$faiserver_host:/srv/fai/config/files/home/ian/.ssh/authorized_keys/GRUB_PC
44 # todo: automatically disable faiserver after a period so
45 # these files are not exposed.
46 s scp -r /q/root/luks /q/root/shadow/traci{,-simple} \
47 root@$faiserver_host:/srv/fai/config/distro-install-common
48 scp /a/bin/devbyid root@$faiserver_host:/srv/fai/nfsroot/usr/local/bin
49 ssh root@$faiserver_host bash <<'EOF'
50 set -eE -o pipefail
51 chmod 644 /srv/fai/config/files/home/ian/.ssh/authorized_keys/GRUB_PC
52 chmod -R a+rX /srv/fai/config/distro-install-common
53 EOF