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