Make username replacement in inittab more robust
[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
12 USERNAME=''
13 [ -r /etc/grml/grml-live.conf ]  && . /etc/grml/grml-live.conf
14 [ -n "$GRML_LIVE_LOCAL_CONFIG" ] && . "$GRML_LIVE_LOCAL_CONFIG"
15 [ -n "$USERNAME" ] || USERNAME=grml
16
17 if ! [ -r $target/etc/runlevel.conf ] ; then
18    echo 'Warning: /etc/runlevel.conf does not exist...'
19    echo '... assuming we do not have file-rc, skipping 15-initsetup'
20    exit 0
21 fi
22
23 # keep a backup of the original runlevel.conf file for reference
24 if [ -r $target/etc/runlevel.conf.original ] ; then
25   # make sure to store old backup files if they differ as well
26   if ! cmp $target/etc/runlevel.conf $target/etc/runlevel.conf.original >/dev/null ; then
27     cp $target/etc/runlevel.conf.original $target/etc/runlevel.conf.original."$(date +%Y%m%d_%k:%M:%S)"
28   fi
29 fi
30
31 cp $target/etc/runlevel.conf $target/etc/runlevel.conf.original
32
33 # provide Grml's default file-rc configuration
34 fcopy -v /etc/runlevel.conf
35
36 # provide Grml's inittab configuration
37 fcopy -v /etc/inittab
38 sed -i "s/\$USERNAME\$/${USERNAME}/" $target/etc/inittab
39
40 # provide Grml's bootlocal init scripts
41 fcopy -v /etc/init.d/bootlocal.first
42 fcopy -v /etc/init.d/bootlocal.middle
43 fcopy -v /etc/init.d/bootlocal.last
44
45 ## END OF FILE #################################################################
46 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2