slitaz-boot-scripts view etc/init.d/rcS @ rev 393

network.sh: better handle WEP connections, handle EAP, store Wi-Fi neworks by default; network.conf: migrate to extended format to support EAP arguments, and few more.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Mar 23 02:01:21 2015 +0200 (2015-03-23)
parents f0e04a0ba4d5
children 7acd64a8f538
line source
1 #!/bin/sh
2 #
3 # /etc/init.d/rcS : Initial boot script for SliTaz GNU/Linux
4 # Configuration file : /etc/rcS.conf
5 #
6 # rcS is the main initialization script used to check fs, mount, clean,
7 # run scripts and start daemons.
8 #
9 . /etc/init.d/rc.functions
10 . /etc/rcS.conf
12 # Set PATH, TZ and boot time.
13 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
14 [ -s /etc/TZ ] && export TZ="$(cat /etc/TZ)"
16 case "$1" in
18 readonly)
20 colorize 34 'Processing: /etc/init.d/rcS...'
22 # Mount /proc
23 echo -n 'Mounting proc filesystem on /proc'
24 mount proc && status
26 # Trigger Udev and handle hotplug events
27 if [ "$UDEV" == "yes" ]; then
28 echo -n 'Mounting devtmpfs filesystem on: /dev'
29 mount -t devtmpfs devtmpfs /dev
30 status
32 echo 'Starting udev daemon...'
33 udevd --daemon 2>/dev/null
35 echo 'Udevadm requesting events from the Kernel...'
36 udevadm trigger
38 echo 'Udevadm waiting for the event queue to finish...'
39 udevadm settle --timeout=120
40 # Disable hotplug helper since udevd listen to netlink
41 echo '' > /proc/sys/kernel/hotplug
42 else
43 echo -n 'Executing mdev -s to populate /dev...'
44 mdev -s && echo 'mdev' > /proc/sys/kernel/hotplug
45 status
46 fi
48 # Before mounting filesystems we check fs specified in the file
49 # /etc/rcS.conf and variable $CHECK_FS. WE need udev started to
50 # have /dev/* populated
51 if [ "$CHECK_FS" ]; then
52 mount -o remount,ro /
53 for i in $CHECK_FS; do
54 colorize 36 "Checking filesystem: $i"
55 e2fsck -p $i
56 done
57 fi
59 # Remount rootfs rw.
60 echo 'Remounting rootfs read/write...'
61 mount -o remount,rw /
62 sync # ensure rw state
64 # Mount filesystems in /etc/fstab.
65 echo 'Mounting filesystems in fstab...'
66 mount -a
67 ;;
70 readwrite)
72 # Be quiet
73 echo '0 0 0 0' > /proc/sys/kernel/printk
75 # Store boot messages to log files.
76 dmesg > /var/log/dmesg.log &
78 # Parse cmdline args for earlier boot options. All other boot options
79 # are in /etc/init./bootopts.sh.
80 echo -n 'Searching for early boot options...'
81 for opt in $(cat /proc/cmdline); do
82 case $opt in
83 modprobe=*)
84 export MODPROBE='yes' ;;
85 config=*)
86 export CONFIG=${opt#config=} ;;
87 screen=*)
88 export SCREEN=${opt#screen=} ;;
89 *)
90 continue ;;
91 esac
92 done
93 status
95 # Clean up the system and set up tmp dirs. */run/* are tmpfs so they are
96 # cleaned up at shutdown.
97 if [ "$CLEAN_UP_SYSTEM" == 'yes' ]; then
98 echo -n 'Cleaning up the system...'
99 rm -rf /tmp
100 mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
101 chmod -R 1777 /tmp
102 status
103 else
104 echo 'System clean up is disabled in: /etc/rcS.conf'
105 fi
107 # Handle kernel cmdline parameter modprobe=<module_list>
108 if [ "$MODPROBE" ]; then
109 mods=$(sed -e 's/.* modprobe=\([^ ]*\).*/\1/' -e 's/,/\n/g' < /proc/cmdline)
110 for i in $mods; do
111 echo -n "Loading kernel module: $i"
112 modprobe $i
113 status
114 done
115 fi
117 # Handle kernel cmdline parameter config=<device>,<path> to source a
118 # disk init script
119 if [ -n "$CONFIG" ]; then
120 DEVICE=${CONFIG%,*}
121 SCRIPT=${CONFIG#*,}
122 echo "Probing $DEVICE... "
123 if ! mount -r $DEVICE /mnt; then
124 if echo $DEVICE | grep -Eq '/dev/sd|UUID=|LABEL='; then
125 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
126 USBDELAY=$((1+$USBDELAY))
127 echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
128 sleep $USBDELAY
129 fi
130 if ! mount -r $DEVICE /mnt; then
131 CONFIG=""
132 fi
133 fi
134 echo -n "Source $SCRIPT from $DEVICE..."
135 if [ -n "$CONFIG" ]; then
136 . /mnt/$SCRIPT
137 umount /mnt 2> /dev/null || true
138 fi
139 status
140 fi
142 # Mount /proc/bus/usb
143 if [ -d /proc/bus/usb ]; then
144 echo -n 'Mounting usbfs filesystem on: /proc/bus/usb'
145 mount -t usbfs usbfs /proc/bus/usb
146 status
147 fi
149 # Start syslogd and klogd
150 echo -n 'Starting system log daemon: syslogd...'
151 syslogd -s $SYSLOGD_ROTATED_SIZE && status
152 echo -n 'Starting kernel log daemon: klogd...'
153 klogd && status
155 # Load all modules listed in config file
156 if [ "$LOAD_MODULES" ]; then
157 colorize 33 'Loading Kernel modules...'
158 for mod in $LOAD_MODULES; do
159 echo -n "Loading module: $mod"
160 modprobe $mod
161 status
162 done
163 fi
165 # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
166 # kernel modules only at first boot or in LiveCD mode.
167 if [ ! -s /var/lib/detected-modules ]; then
168 tazhw init
169 fi
171 # Call udevadm trigger to ensure /dev is fully populated now that all
172 # modules are loaded.
173 if [ "$UDEV" == 'yes' ]; then
174 echo -n 'Triggering udev events: --action=add'
175 udevadm trigger --action=add
176 status
177 fi
179 # Start all scripts specified with $RUN_SCRIPTS
180 for script in $RUN_SCRIPTS; do
181 echo $(colorize 34 "Processing: /etc/init.d/$script")
182 /etc/init.d/$script
183 done
185 # Start X session. Dbus must be started before Xorg and other daemons.
186 # We started it here because X is run before RUN_DAEMONS. Sleep, in
187 # some in live mode we boot too fast and X can't initialize.
188 if [ "$SCREEN" != 'text' ] && [ "$LOGIN_MANAGER" ] &&
189 [ -x /usr/bin/tazx ] && [ -s /etc/slitaz/applications.conf ] &&
190 [ -x "/etc/init.d/$LOGIN_MANAGER" ]; then
191 colorize 36 'Starting X environment...'
192 # We need Xorg 40-Keyboard.conf and SliTaz applications.conf
193 if [ ! -s '/etc/X11/xorg.conf.d/40-Keyboard.conf' ]; then
194 echo 'Configuring Xorg server...' && HOME='/root'
195 tazx init
196 fi
197 /etc/init.d/dbus start
198 (sleep 2; /etc/init.d/${LOGIN_MANAGER} start >/dev/null) &
199 fi
201 # Start all daemons specified with $RUN_DAEMONS
202 if [ "$RUN_DAEMONS" ]; then
203 colorize 33 "Starting all daemons..."
204 for daemon in $RUN_DAEMONS; do
205 [ -x /etc/init.d/$daemon ] &&
206 /etc/init.d/$daemon start
207 done
208 fi
210 # Back to a verbose mode
211 (sleep 6 && echo '7 4 1 7' > /proc/sys/kernel/printk) &
213 if [ "$MESSAGE" ]; then
214 newline
215 colorize 32 "$MESSAGE"
216 fi
217 ;;
219 *)
220 # --> readonly --> readwrite
221 if [ ! -s /run/boot.log ]; then
222 # Mount /run as tmpfs runtime data are not written to disk
223 mount -t tmpfs tmpfs /run
224 # cp -a in tazpkg does not support /var/run symlink
225 mount --bind /run /var/run
226 fi
227 /etc/init.d/rcS readonly 2>&1 | tee -a /run/boot.log
228 # Logrotate boot.log
229 last=.9
230 for i in .8 .7 .6 .5 .4 .3 .2 .1 .0 '' ; do
231 mv -f /var/log/boot.log${i} /var/log/boot.log${last} 2>/dev/null
232 last=$i
233 done
234 mv -f /run/boot.log /var/log/boot.log
235 /etc/init.d/rcS readwrite 2>&1 | tee -a /var/log/boot.log ;;
236 esac