cabf19b4fdc84fbb426b886f7fc45ee19803c6ef
[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 grml-boot.target
28 }
29
30 file_rc_setup() {
31   if ! [ -r "${target}"/etc/runlevel.conf ] ; then
32      echo 'Warning: /etc/runlevel.conf does not exist...'
33      echo '... assuming we do not have file-rc, skipping 15-initsetup'
34      exit 0
35   fi
36
37   # keep a backup of the original runlevel.conf file for reference
38   if [ -r "${target}"/etc/runlevel.conf.original ] ; then
39     # make sure to store old backup files if they differ as well
40     if ! cmp "${target}"/etc/runlevel.conf "${target}"/etc/runlevel.conf.original >/dev/null ; then
41       cp "${target}"/etc/runlevel.conf.original "${target}/etc/runlevel.conf.original.$(date +%Y%m%d_%k:%M:%S)"
42     fi
43   fi
44
45   cp "${target}"/etc/runlevel.conf "${target}"/etc/runlevel.conf.original
46
47   # provide Grml's default file-rc configuration
48   fcopy -v /etc/runlevel.conf
49
50   # provide Grml's inittab configuration
51   fcopy -v /etc/inittab
52   sed -i "s/\$USERNAME\$/${USERNAME}/" "${target}"/etc/inittab
53
54   # provide Grml's bootlocal init scripts
55   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.first
56   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.middle
57   fcopy -v -mroot,root,0755 /etc/init.d/bootlocal.last
58 }
59
60 if ifclass FILE_RC ; then
61   file_rc_setup
62 else
63   systemd_setup
64 fi
65
66 ## END OF FILE #################################################################
67 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2