fix various arch issues
[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 faiserver_host=faiserver
14 # i use faiserver as a dns alias, but ssh key is associated with
15 # a canonical hostname and we will have ssh warning spam unless we
16 # use it, so look it up.
17 if addr=$(host faiserver); then
18 addr=${addr##* }
19 if h=$(host $addr); then
20 h=${h##* }
21 faiserver_host=${h%%.*}
22 else
23 echo "$0: warning: host \$addr($addr) failed"
24 fi
25 else
26 echo "$0: warning: host faiserver failed"
27 fi
28
29
30 ssh root@$faiserver_host rm -rf /srv/fai/config
31 scp -r fai/config root@$faiserver_host:/srv/fai
32 # fai example pass: fai
33 #ROOTPW='$1$kBnWcO.E$djxB128U7dMkrltJHPf6d1'
34
35 # generating a hashed password:
36 # under debian, you can do
37 # echo "yoursecrectpassword" | mkpasswd -m sha-512 -s
38 # On arch, best seems to be copy your shadow file to a temp location,
39 # then passwd, get out the new pass, then copy the shadow file back.
40
41 f=/q/root/shadow/standard
42 if s test -e $f; then
43 ssh root@$faiserver_host tee -a /srv/fai/config/class/DEFAULT.var <<EOF
44 ROOTPW='$(s cat $f)'
45 EOF
46 fi
47
48 tpvar="$(s cat /q/root/shadow/traci-simple)"
49 ssh root@$faiserver_host tee -a /srv/fai/config/class/tp.var <<EOF
50 ROOTPW='$tpvar'
51 EOF
52
53 scp ~/.ssh/id_rsa.pub \
54 root@$faiserver_host:/srv/fai/config/files/home/ian/.ssh/authorized_keys/GRUB_PC
55 # todo: automatically disable faiserver after a period so
56 # these files are not exposed.
57 s scp -r /q/root/luks /q/root/shadow/traci{,-simple} \
58 root@$faiserver_host:/srv/fai/config/distro-install-common
59 scp /a/bin/devbyid root@$faiserver_host:/srv/fai/nfsroot/usr/local/bin
60 ssh root@$faiserver_host bash <<'EOF'
61 set -eE -o pipefail
62 chmod 644 /srv/fai/config/files/home/ian/.ssh/authorized_keys/GRUB_PC
63 chmod -R a+rX /srv/fai/config/distro-install-common
64 EOF