cleanup classes, populate ssh server keys
[automated-distro-installer] / fai / config / scripts / GRUB_PC / 11-ian
1 #!/bin/bash -x
2
3 set -eE -o pipefail
4 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
5
6 if [[ $EUID != 0 ]]; then
7 echo "$0: error: expected to be root."
8 exit 1
9 fi
10
11 if ! type -t fcopy &>/dev/null; then
12 sudo apt-get -y install fai-client
13 fi
14
15 chroot $FAI_ROOT bash <<'EOFOUTER'
16 if getent group systemd-journal >/dev/null; then
17 # makes the journal be saved to disk.
18 mkdir -p /var/log/journal
19 chmod 755 /var/log/journal
20 fi
21 debconf-set-selections <<EOF
22 kexec-tools kexec-tools/load_kexec boolean false
23 EOF
24 apt-get install -y pxe-kexec
25 EOFOUTER
26
27 # -r = recursive
28 # -i = ignore non-matching class warnings, always exit 0
29 # -B = no backup files
30 fcopy -riB /boot
31 # this is also done by FABASE/10-misc by default.
32 fcopy -riB /root
33 if ifclass STABLE_BOOTSTRAP; then
34 fcopy -ri /etc/systemd/system
35 chroot $FAI_ROOT bash <<'EOFOUTER'
36 systemctl enable fai_check.service
37 EOFOUTER
38 exit 0
39 fi
40
41 bind-common() {
42 src=$1
43 dst=$2
44 if [[ ! -e $dst && -e $src ]]; then
45 mkdir -p $dst
46 mount -o bind $src $dst
47 fi
48
49 }
50 bind-common $FAI/distro-install-common/shadow /q/root/shadow
51
52 # todo, port this over to the arch install script.
53 cp -rT $FAI/distro-install-common/p/c/machine_specific/$HOSTNAME/filesystem/etc/ssh /target/etc/ssh
54
55 $FAI/distro-install-common/end
56
57 # these get copied in an earlier stage by fai, but leaving it here since
58 # I run this as a single post-fai script to update things that have changed.
59 fcopy -riB /etc/apt
60 $ROOTCMD apt-get update
61
62 fcopy -riB /etc/ssh
63
64 chroot $FAI_ROOT bash <<'EOF'
65 set -eE -o pipefail
66 mkdir -p /home/ian/.ssh
67 f=/root/.ssh/authorized_keys
68 if [[ -e $f ]]; then
69 cp $f /home/ian/.ssh
70 fi
71 chown -R 1000:1000 /home/ian/.ssh
72 chmod -R u=Xrw,og= /home/ian/.ssh
73 rm -rf /root/.ssh
74 cp -rL /home/ian/.ssh /root
75 chown -R root:root /root/.ssh
76 chmod 700 /root/.ssh
77
78
79 # default jessie groups + kvm, systemd-journal, adm
80 usermod -aG adm,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev ian
81
82 if getent group systemd-journal >/dev/null; then
83 usermod -aG systemd-journal ian
84 fi
85 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
86 # it suggests not having plymouth-theme-ubuntu-text, but
87 # making it not installed then kills plymouth, then makes
88 # the system not boot.
89 sed -ri 's/(^ *GRUB_CMDLINE_LINUX.*)quiet splash/\1/' /etc/default/grub
90 # on xenial, no grub is displayed at all. fix that.
91 # found just by noticing this in the config file, and a
92 # warning about it in error.log
93 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
94 update-grub2
95 EOF
96
97
98 # reading through the groups that ian is in but traci isn't,
99 for g in plugdev audio video cdrom; do
100 $ROOTCMD usermod -a -G $g traci
101 done