various fixes for bullseye and new ssh key changes
[automated-distro-installer] / fai / config / hooks / instsoft.DEFAULT
1 #!/bin/bash
2
3 # These are things we can do before package_config packages get installed.
4
5 # exit for any vm except demohost, or if we are doing a dirinstall
6 if ifclass VM && ! ifclass demohost || ifclass VOL_BULLSEYE_BOOTSTRAP || [[ ! $FAI_ACTION || $FAI_ACTION = dirinstall ]]; then
7 exit 0
8 fi
9
10 keyfile=/var/lib/fai/config/distro-install-common/luks/host-$HOSTNAME
11 f=$target/root/keyscript
12 cat > $f <<EOFOUTER
13 #!/bin/sh
14 cat <<'EOF'
15 $(cat $keyfile)
16 EOF
17 EOFOUTER
18 chmod 700 $f
19
20
21 # for hosts which don't have these data volumes, copy the specific
22 # files we need.
23 if ifclass demohost; then
24 files=(/var/lib/fai/config/distro-install-common/luks/host-demohost)
25 elif ifclass tp; then
26 files=(/var/lib/fai/config/distro-install-common/luks/host-tp)
27 fi
28 if [[ ${files[0]} ]]; then
29 d=$target/q/root/luks
30 mkdir -p $d
31 chmod 700 $d
32 cp -p ${files[@]} $d
33 fi
34
35
36 #### this bit is duplicated in rootsshsync, except we skip update-initramfs,
37 # since I suspect its not needed. I'm not sure any of this is needed
38 # since we initially embed the key, and with distro-begin, we run rootsshsync
39 # around the same time as we remove it.
40 d=/etc/initramfs-tools
41 if [[ -e $d ]] && ! diff -q /root/.ssh/authorized_keys $d/root/.ssh/authorized_keys &>/dev/null; then
42 mkdir -p $d/root/.ssh /etc/dropbear-initramfs
43 chmod 700 $d/root $d/root/.ssh
44 cp -p /root/.ssh/authorized_keys $d/root/.ssh/authorized_keys
45 cp -p /root/.ssh/authorized_keys /etc/dropbear-initramfs
46 if [[ -e /root/.ssh/authorized_keys2 ]]; then
47 cat /root/.ssh/authorized_keys2 >>/etc/dropbear-initramfs
48 fi
49 fi