bec56087b6b880499106aa5ef12a78f3f2039b59
[live-boot-grml.git] / scripts / live-bottom / 25configure_init
1 #!/bin/sh
2
3 #set -e
4
5 # initramfs-tools header
6
7 PREREQ=""
8
9 prereqs()
10 {
11         echo "${PREREQ}"
12 }
13
14 case "${1}" in
15         prereqs)
16                 prereqs
17                 exit 0
18                 ;;
19 esac
20
21 # live-initramfs header
22
23 . /scripts/live-functions
24
25 log_begin_msg "Setting up init..."
26
27 # live-initramfs script
28
29 # Arrange for shells on virtual consoles, rather than login prompts
30
31 if [ -z "${NOAUTOLOGIN}" ]
32 then
33         if [ -n "${USERNAME}" ]
34         then
35                 if [ ! -z "${LIVE_GETTY}" ]
36                 then
37                         if echo "${DEFCONSOLE}" | grep -qs ttyS
38                         then
39                                 # AUTOMATIC SERIAL CONSOLE #
40                                 PORT=$(echo "${DEFCONSOLE}" | \
41                                         sed -e 's%,.*%%')
42                                 SPEED=$(echo "${DEFCONSOLE}" | \
43                                         sed -e 's%ttyS[0-9]\+,%%' \
44                                         -e's%\([0-9]\+\).*%\1%')
45
46                                 if ! ( sed -n -e'/^[^#]/p' /root/etc/inittab | grep -qs ":respawn:/sbin/getty.*${PORT}" )
47                                 then
48                                         IDs="A B C D E F G H I J K L M N O P Q R S T Q U V V X Y Z 0 1 2 3 4 5 6 7 8 9"
49
50                                         for ID1 in ${IDs}
51                                         do
52                                                 for ID2 in ${IDs}
53                                                 do
54                                                         ID="${ID1}${ID2}"
55
56                                                         if ! grep "^${ID}:" /etc/inittab
57                                                         then
58                                                                 #make sure it is not already in use
59                                                                 break 2
60                                                         fi
61                                                 done
62                                         done
63
64                                         echo "${ID}:2345:respawn:/sbin/live-getty -L ${PORT} ${SPEED} vt100" >> /root/etc/inittab
65                                 fi
66                         fi
67
68                         if [ -f /root/etc/inittab ]
69                         then
70                                 sed -i -e'/^[^#]/s%respawn:/sbin/getty%respawn:/sbin/live-getty%' /root/etc/inittab
71                         fi
72                 else
73                         if [ -f /root/etc/inittab ]
74                         then
75                                 sed -i -e "s|^\([^:]*:[^:]*:[^:]*\):.*getty.*\<\(tty[0-9]*\).*$|\1:/bin/login -f ${USERNAME} </dev/\2 >/dev/\2 2>\&1|" /root/etc/inittab
76                         fi
77
78                         if [ "/root/etc/event.d/tty*" != "$(echo /root/etc/event.d/tty*)" ]
79                         then
80                                 for f in /root/etc/event.d/tty*
81                                 do
82                                         sed -i -e "s|^respawn.*|respawn /bin/login -f ${USERNAME} </dev/$(basename ${f}) > /dev/$(basename ${f}) 2>\&1|" ${f}
83                                 done
84
85                                 if [ "${BUILD_SYSTEM}" = "Ubuntu" ]
86                                 then
87                                         for x in $(cat /proc/cmdline)
88                                         do
89                                                 case ${x} in
90                                                         noninteractive)
91                                                                 sed -i -e "s|^exec.*|exec /usr/bin/ubiquity noninteractive </dev/tty1 > /dev/tty1 2>\&1|" /root/etc/event.d/tty1
92                                                                 rm -f /root/etc/rc?.d/[SK]??[gkx]dm
93                                                                 ;;
94
95                                                         textonly)
96                                                                 rm -f /root/etc/rc?.d/[SK]??[gkx]dm
97                                                                 ;;
98                                                 esac
99                                         done
100                                 fi
101                         fi
102                 fi
103
104                 # Since we use autologin, lastlog doesn't make sense on the console.
105                 sed -i '/^[^#].*pam_lastlog\.so/s/^/# /' /root/etc/pam.d/login
106         fi
107 fi
108
109 # do not try to remove files if using file-rc
110 if [ -d /etc/rc0.d ]
111 then
112         # This has the nice side effect of the cron.{daily,weekly,monthly} jobs in
113         # /etc/crontab remaining disabled, yet also not run by anacron
114         if [ -x /root/usr/sbin/anacron ]
115         then
116                 chroot /root dpkg-divert --add --rename --quiet /usr/sbin/anacron
117                 ln -s /bin/true /usr/sbin/anacron
118         fi
119
120         # No point, really
121         rm -f /root/etc/rc?.d/[SK]??postfix
122
123         # Avoid clobbering the user's clock
124         rm -f /root/etc/rc?.d/K??hwclock.sh
125 fi
126
127 # Disable readahead since it doesn't play well with squashfs + unionfs
128 # use chmod instead of mv to not trigger unionfs bugs.
129 if [ -e /root/sbin/readahead-list ]
130 then
131         chmod -x /root/sbin/readahead-list
132 fi
133
134 log_end_msg
135
136 exit 0