slitaz-boot-scripts view etc/init.d/bootopts.sh @ rev 158

rcS: get all earlier boot option at one time + home= wait for kernel usb delay
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 26 15:13:25 2009 +0200 (2009-04-26)
parents 965cc9d8722a
children 30b287d766bf
line source
1 #!/bin/sh
2 # /etc/init.d/bootopts.sh - SliTaz boot options from the cmdline.
3 #
4 # Earlier boot options are in rcS: config= and modprobe=
5 #
6 . /etc/init.d/rc.functions
8 # Update fstab for swapon/swapoff
9 add_swap_in_fstab()
10 {
11 grep -q "$1 " /etc/fstab || cat >> /etc/fstab <<EOT
12 $1 swap swap default 0 0
13 EOT
14 }
16 # Check if swap file must be generated in /home: swap=size (Mb).
17 # This option is used with home=device.
18 gen_home_swap()
19 {
20 if grep -q "swap=[1-9]*" /proc/cmdline; then
21 SWAP_SIZE=`cat /proc/cmdline | sed 's/.*swap=\([^ ]*\).*/\1/'`
22 # DD to gen a virtual disk.
23 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
24 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
25 # Make the Linux swap filesystem.
26 mkswap /home/swap
27 add_swap_in_fstab /home/swap
28 fi
29 }
31 # Mount /home and check for user hacker home dir.
32 #
33 mount_home()
34 {
35 echo "Home has been specified to $DEVICE..."
36 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
37 USBDELAY=$((1+$USBDELAY))
38 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
39 sleep $USBDELAY
40 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
41 DEVID=$DEVICE
42 if [ -x /sbin/blkid ]; then
43 # Can be label, uuid or devname. DEVID give us first: /dev/name.
44 DEVID=`/sbin/blkid | grep $DEVICE | cut -d: -f1`
45 DEVID=${DEVID##*/}
46 fi
47 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
48 echo "Mounting /home on /dev/$DEVID... "
49 mv /home/$USER /tmp/$USER-files
50 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
51 || mount /dev/$DEVID /home
52 gen_home_swap
53 else
54 echo "Unable to find $DEVICE... "
55 fi
56 # Move all hacker dir if needed.
57 if [ ! -d "/home/$USER" ] ; then
58 mv /tmp/$USER-files /home/$USER
59 chown -R $USER.$USER /home/$USER
60 else
61 rm -rf /tmp/$USER-files
62 fi
63 }
65 # Mount all ext3 partitions found (opt: mount).
66 mount_partitions()
67 {
68 # Get the list of partitions.
69 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
70 # Mount filesystems rw.
71 for device in $DEVICES_LIST
72 do
73 name=${device#/dev/}
74 # Device can be already used by home=usb.
75 if ! mount | grep ^$device >/dev/null; then
76 echo "Mounting partition: $name on /mnt/$name"
77 mkdir /mnt/$name
78 mount $device /mnt/$name
79 fi
80 done
81 }
83 # Parse /proc/cmdline with grep.
84 #
86 echo "Parsing kernel cmdline for SliTaz live options... "
88 # eject: Eject cdrom
89 if grep -q -w "eject" /proc/cmdline; then
90 eject /dev/cdrom
91 fi
93 # user=name: Default user account without password (uid=1000).
94 #
95 if ! grep -q "1000:1000" /etc/passwd; then
96 if grep -q "user=" /proc/cmdline; then
97 USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
98 # Avoid usage of an existing system user or root.
99 if grep -q ^$USER /etc/passwd; then
100 USER=tux
101 fi
102 else
103 USER=tux
104 fi
105 echo -n "Configuring user and group: $USER..."
106 echo "$USER:x:1000:1000:SliTaz User,,,:/home/$USER:/bin/sh" >> /etc/passwd
107 echo "$USER::14035:0:99999:7:::" >> /etc/shadow
108 echo "$USER:x:1000:" >> /etc/group
109 echo "$USER:!::" >> /etc/gshadow
110 status
111 # Audio group.
112 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
113 # /home/$USER files from /etc/skel.
114 if [ -d /etc/skel ]; then
115 cp -a /etc/skel /home/$USER
116 # Path for user desktop files.
117 for i in /home/$USER/.local/share/applications/*.desktop
118 do
119 sed -i s/"user_name"/"$USER"/g $i
120 done
121 else
122 mkdir -p /home/$USER
123 fi
124 # set permissions.
125 chown -R $USER.$USER /home/$USER
126 # Slim default user.
127 if [ -f /etc/slim.conf ]; then
128 sed -i s/"default_user .*"/"default_user $USER"/\
129 /etc/slim.conf
130 fi
131 fi
133 # Autologin option to skip first graphic login prompt.
134 if grep -q "autologin" /proc/cmdline; then
135 echo "auto_login yes" >> /etc/slim.conf
136 fi
138 # Check for a specified home directory on cmdline (home=*).
139 #
140 if grep -q "home=usb" /proc/cmdline; then
141 DEVICE=sda1
142 mount_home
143 elif grep -q "home=" /proc/cmdline; then
144 DEVICE=`cat /proc/cmdline | sed 's/.*home=\([^ ]*\).*/\1/'`
145 mount_home
146 fi
148 # Activate an eventual swap file in /home and on local HD.
149 #
150 if [ "`fdisk -l | grep swap`" ]; then
151 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
152 echo "Swap memory detected on: $SWAP_DEV"
153 add_swap_in_fstab $SWAP_DEV
154 done
155 fi
156 if grep -q swap /etc/fstab; then
157 echo "Activating swap memory..."
158 swapon -a
159 fi
161 # Check for a specified locale (lang=*).
162 #
163 if grep -q "lang=*" /proc/cmdline; then
164 LANG=`cat /proc/cmdline | sed 's/.*lang=\([^ ]*\).*/\1/'`
165 echo -n "Setting system locale to: $LANG... "
166 echo "LANG=$LANG" > /etc/locale.conf
167 echo "LC_ALL=$LANG" >> /etc/locale.conf
168 status
169 fi
171 # Check for a specified keymap (kmap=*).
172 #
173 if grep -q "kmap=*" /proc/cmdline; then
174 KEYMAP=`cat /proc/cmdline | sed 's/.*kmap=\([^ ]*\).*/\1/'`
175 echo -n "Setting system keymap to: $KEYMAP..."
176 echo "$KEYMAP" > /etc/keymap.conf
177 status
178 fi
180 # Laptop option to load ac and battery Kernel modules.
181 if grep -q "laptop" /proc/cmdline; then
182 echo "Loading laptop modules: ac, battery, yenta_socket..."
183 modprobe ac
184 modprobe battery
185 modprobe yenta_socket
186 fi
188 # Check for a Window Manager (for a flavor, default WM can be changed
189 # with boot option or with an addfile in /etc/X11/wm.default.
190 if grep -q "wm=" /proc/cmdline; then
191 mkdir -p /etc/X11
192 WM=`cat /proc/cmdline | sed 's/.*wm=\([^ ]*\).*/\1/'`
193 case $WM in
194 jwm)
195 echo "jwm" > /etc/X11/wm.default ;;
196 ob|openbox|openbox-session)
197 echo "openbox" > /etc/X11/wm.default ;;
198 e17|enlightenment|enlightenment_start)
199 echo "enlightenment" > /etc/X11/wm.default ;;
200 esac
201 else
202 # If no default WM fallback to Openbox.
203 if [ ! -f /etc/X11/wm.default ]; then
204 echo "openbox" > /etc/X11/wm.default
205 fi
206 fi
208 # Check for option mount.
209 if grep -q "mount" /proc/cmdline; then
210 mount_partitions
211 fi
213 # Mount and install packages-XXX.iso (usefull without Internet connection)
214 if grep -q " mount-packages" /proc/cmdline; then
215 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
216 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
217 [ -z "$PKGDEV" -a -L /dev/cdrom ] && PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
218 if [ -n "$PKGDEV" ]; then
219 echo -n "Mounting packages archive from $PKGDEV..."
220 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
221 status
222 /packages/install.sh
223 fi
224 fi