4d9acfc0b4ace35191dcac59ae0006c1a2c37a11
[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 -M -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   # FIXME - ssh-keygen isn't executed yet before ssh-bootoption + ssh services
20   $ROOTCMD systemctl enable ssh-bootoption.service || echo "failed to enable ssh-bootoption.service"
21   $ROOTCMD systemctl enable ssh-keygen.service     || echo "failed to enable ssh-keygen.service"
22
23   # fails on overlayfs with
24   # "Failed to unmount transient /etc/machine-id file in our private namespace: Invalid argument"
25   $ROOTCMD systemctl mask systemd-machine-id-commit.service || echo "failed to mask $systemd-machine-id-commit.service"
26
27   # TODO ->
28
29   # * *proper* integration for grml-autoconfig
30       $ROOTCMD systemctl enable grml-autoconfig.service || echo "failed to enable grml-autoconfig.service"
31       ln -sf /etc/systemd/system/grml-autoconfig.service "${target}"/etc/systemd/system/multi-user.target.wants/grml-autoconfig.service
32
33   # * avoid startup of any LSB scripts; NOTE: jessie doesn't support that
34   #   system-generators approach yet, only >=stretch
35       mkdir -p "${target}"/etc/systemd/system-generators/
36       ln -sf /dev/null "${target}"/etc/systemd/system-generators/systemd-sysv-generator
37   #   -> revert /etc/systemd/system-generators/systemd-sysv-generator && systemctl daemon-reload during *bootup*
38   #      + possibly move this into startup so it's always executed on bootup, even with persistency enabled
39   #      where the change towards systemd-sysv-generator might persist across
40   #      reboots -> LSB scripts executed on reboots
41 }
42
43 file_rc_setup() {
44   if ! [ -r "${target}"/etc/runlevel.conf ] ; then
45      echo 'Warning: /etc/runlevel.conf does not exist...'
46      echo '... assuming we do not have file-rc, skipping 15-initsetup'
47      exit 0
48   fi
49
50   # keep a backup of the original runlevel.conf file for reference
51   if [ -r "${target}"/etc/runlevel.conf.original ] ; then
52     # make sure to store old backup files if they differ as well
53     if ! cmp "${target}"/etc/runlevel.conf "${target}"/etc/runlevel.conf.original >/dev/null ; then
54       cp "${target}"/etc/runlevel.conf.original "${target}/etc/runlevel.conf.original.$(date +%Y%m%d_%k:%M:%S)"
55     fi
56   fi
57
58   cp "${target}"/etc/runlevel.conf "${target}"/etc/runlevel.conf.original
59
60   # provide Grml's default file-rc configuration
61   fcopy -v /etc/runlevel.conf
62
63   # provide Grml's inittab configuration
64   fcopy -v /etc/inittab
65   sed -i "s/\$USERNAME\$/${USERNAME}/" "${target}"/etc/inittab
66
67   # provide Grml's bootlocal init scripts
68   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.first
69   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.middle
70   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.last
71 }
72
73 if ifclass FILE_RC ; then
74   file_rc_setup
75 else
76   systemd_setup
77 fi
78
79 ## END OF FILE #################################################################
80 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2