949f1817627b1450732694ee90b23193335cb909
[automated-distro-installer] / fai / config / scripts / GRUB_PC / 11-iank
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
34
35 src=$FAI/distro-install-common/shadow
36 dst=/q/root/shadow
37 if [[ ! -e $dst && -e $src ]]; then
38 # outside of fai context, we skip this
39 mkdir -p $dst
40 mount -o bind $src $dst
41 fi
42
43 $FAI/distro-install-common/end
44 if ifclass VOL_STABLE_BOOTSTRAP; then
45 fcopy -ri /etc/systemd/system
46 chroot $FAI_ROOT bash <<'EOFOUTER'
47 systemctl enable fai_check.service
48 EOFOUTER
49 exit 0 # avoid unnecessary stuff in bootstrap vol
50 fi
51
52
53 # these get copied in an earlier stage by fai, but leaving it here since
54 # I run this as a single post-fai script to update things that have changed.
55 fcopy -riB /etc/apt
56 # outside of fai, this seems to regularly lead to
57 # E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
58 # so add a sleep. 1 sec is probably way more than needed.
59 sleep 1
60 $ROOTCMD apt-get update
61
62
63 chroot $FAI_ROOT bash <<'EOF'
64 set -eE -o pipefail
65 mkdir -p /home/iank/.ssh
66 f=/root/.ssh/authorized_keys
67 if [[ -e $f ]]; then
68 cp $f /home/iank/.ssh
69 fi
70 chown -R 1000:1000 /home/iank/.ssh
71 chmod -R u=Xrw,og= /home/iank/.ssh
72 rm -rf /root/.ssh
73 cp -rL /home/iank/.ssh /root
74 chown -R root:root /root/.ssh
75 chmod 700 /root/.ssh
76
77
78 # default jessie groups + kvm, systemd-journal, adm
79 usermod -aG adm,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev iank
80
81 if getent group systemd-journal >/dev/null; then
82 usermod -aG systemd-journal iank
83 fi
84 # https://askubuntu.com/questions/33416/how-do-i-disable-the-boot-splash-screen-and-only-show-kernel-and-boot-text-inst
85 # it suggests not having plymouth-theme-ubuntu-text, but
86 # making it not installed then kills plymouth, then makes
87 # the system not boot.
88 sed -ri 's/(^ *GRUB_CMDLINE_LINUX.*)quiet splash/\1/' /etc/default/grub
89 # on xenial, no grub is displayed at all. fix that.
90 # found just by noticing this in the config file, and a
91 # warning about it in error.log
92 sed -i '/^ *GRUB_HIDDEN_TIMEOUT/d' /etc/default/grub
93 update-grub2
94
95 # this is usefull. Only thing reason I see this being disabled by default is
96 # that a normal user can disrupt the system, eg cause a reboot.
97 sed -i '$a kernel.sysrq=1
98 /^kernel.sysrq=/d' /etc/sysctl.conf
99 EOF
100
101
102 # reading through the groups that iank is in but traci isn't,
103 for g in plugdev audio video cdrom; do
104 $ROOTCMD usermod -a -G $g traci
105 done