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