f94cd3fa1dd670ef663b3a73a268f88c7e080037
[grml-live.git] / etc / grml / fai / config / scripts / GRMLBASE / 15-initsetup
1 #!/bin/bash
2 # Filename:      ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/15-initsetup
3 # Purpose:       configure init system for the live-system
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 ################################################################################
8
9 set -u
10 set -e
11 . "$GRML_LIVE_CONFIG"
12
13 systemd_setup() {
14   fcopy -i -B -v -r /etc/systemd
15
16   echo "Enabling user '$USERNAME' for autologin"
17   sed -i "s/\$USERNAME/$USERNAME/" "$target"/etc/systemd/system/getty@tty*.service.d/override.conf
18
19   # enable TTY logins
20   local service
21   for file in "${target}"/etc/systemd/system/getty@tty*.service.d ; do
22     service=$(basename "$file" .d)
23     $ROOTCMD systemctl enable "$service" || echo "failed to enable $service"
24   done
25   unset service
26
27   # FIXME - ssh-keygen isn't executed yet before ssh-bootoption + ssh services
28   $ROOTCMD systemctl enable ssh-bootoption.service || echo "failed to enable ssh-bootoption.service"
29   $ROOTCMD systemctl enable ssh-keygen.service     || echo "failed to enable ssh-keygen.service"
30
31   # fails on overlayfs with
32   # "Failed to unmount transient /etc/machine-id file in our private namespace: Invalid argument"
33   $ROOTCMD systemctl mask systemd-machine-id-commit.service || echo "failed to mask $systemd-machine-id-commit.service"
34
35   # disable unwanted services
36   local service
37   for service in \
38     cron.service \
39     lvm2-lvmetad.service \
40     lvm2-lvmetad.socket \
41     lvm2-lvmpolld.socket \
42     lvm2-monitor.service \
43     mdadm-raid.service \
44     smartd.service \
45     ssh.service \
46     swap.target \
47     systemd-timesyncd.service \
48     uuidd.service
49   do
50     $ROOTCMD systemctl disable ${service} || echo "failed to disable $service"
51   done
52   unset service
53
54   # TODO ->
55
56   # * *proper* integration for grml-autoconfig
57       $ROOTCMD systemctl enable grml-autoconfig.service || echo "failed to enable grml-autoconfig.service"
58       ln -sf /etc/systemd/system/grml-autoconfig.service "${target}"/etc/systemd/system/multi-user.target.wants/grml-autoconfig.service
59
60   # * avoid startup of any LSB scripts; NOTE: jessie doesn't support that
61   #   system-generators approach yet, only >=stretch
62       mkdir -p "${target}"/etc/systemd/system-generators/
63       ln -sf /dev/null "${target}"/etc/systemd/system-generators/systemd-sysv-generator
64   #   -> revert /etc/systemd/system-generators/systemd-sysv-generator && systemctl daemon-reload during *bootup*
65   #      + possibly move this into startup so it's always executed on bootup, even with persistency enabled
66   #      where the change towards systemd-sysv-generator might persist across
67   #      reboots -> LSB scripts executed on reboots
68 }
69
70 file_rc_setup() {
71   if ! [ -r "${target}"/etc/runlevel.conf ] ; then
72      echo 'Warning: /etc/runlevel.conf does not exist...'
73      echo '... assuming we do not have file-rc, skipping 15-initsetup'
74      exit 0
75   fi
76
77   # keep a backup of the original runlevel.conf file for reference
78   if [ -r "${target}"/etc/runlevel.conf.original ] ; then
79     # make sure to store old backup files if they differ as well
80     if ! cmp "${target}"/etc/runlevel.conf "${target}"/etc/runlevel.conf.original >/dev/null ; then
81       cp "${target}"/etc/runlevel.conf.original "${target}/etc/runlevel.conf.original.$(date +%Y%m%d_%k:%M:%S)"
82     fi
83   fi
84
85   cp "${target}"/etc/runlevel.conf "${target}"/etc/runlevel.conf.original
86
87   # provide Grml's default file-rc configuration
88   fcopy -v /etc/runlevel.conf
89
90   # provide Grml's inittab configuration
91   fcopy -v /etc/inittab
92   sed -i "s/\$USERNAME\$/${USERNAME}/" "${target}"/etc/inittab
93
94   # provide Grml's bootlocal init scripts
95   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.first
96   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.middle
97   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.last
98 }
99
100 if ifclass FILE_RC ; then
101   file_rc_setup
102 else
103   systemd_setup
104 fi
105
106 ## END OF FILE #################################################################
107 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2