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

bootopts.sh: try to shortcut USBDELAY
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Feb 05 19:20:24 2011 +0100 (2011-02-05)
parents fcdf41a689c8
children 06704c29c449
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, ex: 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 # Default user account without password (uid=1000). In live mode the option
17 # user=name can be used, but user must be added before home= to have home dir.
18 # This option is not handled by a loop and case like others and has no
19 # effect on an installed system.
20 if ! grep -q "100[0-9]:100[0-9]" /etc/passwd; then
21 if grep -q "user=" /proc/cmdline; then
22 USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
23 # Avoid usage of an existing system user or root.
24 if grep -q ^$USER /etc/passwd; then
25 USER=tux
26 fi
27 else
28 USER=tux
29 fi
30 echo -n "Configuring user and group: $USER..."
31 echo "$USER:x:1000:1000:SliTaz User,,,:/home/$USER:/bin/sh" >> /etc/passwd
32 echo "$USER::14035:0:99999:7:::" >> /etc/shadow
33 echo "$USER:x:1000:" >> /etc/group
34 echo "$USER:!::" >> /etc/gshadow
35 status
36 # Audio and cdrom group.
37 addgroup $USER audio
38 addgroup $USER cdrom
39 addgroup $USER video
40 # /home/$USER files from /etc/skel.
41 if [ -d /etc/skel ]; then
42 cp -a /etc/skel /home/$USER
43 # Path for user desktop files.
44 for i in /home/$USER/.local/share/applications/*.desktop
45 do
46 sed -i s/"user_name"/"$USER"/g $i
47 done
48 else
49 mkdir -p /home/$USER
50 fi
51 # Set permissions.
52 chown -R $USER.users /home/$USER
53 # Slim default user.
54 if [ -f /etc/slim.conf ]; then
55 sed -i s/"default_user .*"/"default_user $USER"/\
56 /etc/slim.conf
57 fi
58 fi
60 # Parse /proc/cmdline for boot options.
61 echo "Parsing kernel cmdline for SliTaz live options... "
63 for opt in `cat /proc/cmdline`
64 do
65 case $opt in
66 eject)
67 # Eject cdrom.
68 eject /dev/cdrom ;;
69 autologin)
70 # Autologin option to skip first graphic login prompt.
71 echo "auto_login yes" >> /etc/slim.conf ;;
72 lang=*)
73 # Check for a specified locale (lang=*).
74 LANG=${opt#lang=}
75 echo -n "Setting system locale to: $LANG... "
76 echo "LANG=$LANG" > /etc/locale.conf
77 echo "LC_ALL=$LANG" >> /etc/locale.conf
78 [ ! -d /usr/lib/locale/$LANG ] && localedef \
79 -i $LANG -c -f UTF-8 /usr/lib/locale/$LANG &
80 tazlocale link-files
81 status ;;
82 kmap=*)
83 # Check for a specified keymap (kmap=*).
84 KEYMAP=${opt#kmap=}
85 echo -n "Setting system keymap to: $KEYMAP..."
86 echo "$KEYMAP" > /etc/keymap.conf
87 status ;;
88 home=*)
89 # Check for a specified home partition (home=*) and check for
90 # user home dir. Note: home=usb is a shorter and easier way to
91 # have home=/dev/sda1.
92 DEVICE=${opt#home=}
93 [ "$DEVICE" = "usb" ] && DEVICE=sda1
94 echo "Home has been specified to $DEVICE..."
95 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
96 if [ -z "$DEVID" ]; then
97 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
98 USBDELAY=$((2+$USBDELAY))
99 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
100 sleep $USBDELAY
101 fi
102 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
103 DEVID=$DEVICE
104 if [ -x /sbin/blkid ]; then
105 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
106 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
107 fi
108 DEVID=${DEVID##*/}
109 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
110 echo "Mounting /home on /dev/$DEVID... "
111 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
112 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
113 || mount /dev/$DEVID /home
114 # Check if swap file must be generated in /home: swap=size (Mb).
115 # This option is only used within home=device.
116 if grep -q "swap=[1-9]*" /proc/cmdline; then
117 SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
118 # DD to gen a virtual disk.
119 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
120 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
121 # Make the Linux swap filesystem.
122 mkswap /home/swap
123 add_swap_in_fstab /home/swap
124 fi
125 else
126 echo "Unable to find $DEVICE... "
127 fi
128 # Move all user dir if needed.
129 if [ ! -d "/home/$USER" ] ; then
130 mv /tmp/$USER-files /home/$USER
131 chown -R $USER.users /home/$USER
132 else
133 rm -rf /tmp/$USER-files
134 fi
135 # Install all packages in /home/boot/packages. In live CD and
136 # USB mode the option home= mounts the device on /home, so we
137 # already have a boot directory with the Kernel and rootfs.
138 if [ -d "/home/boot/packages" ]; then
139 for pkg in /home/boot/packages/*.tazpkg
140 do
141 tazpkg install $pkg
142 done
143 fi
144 # We can have custom files in /home/boot/rootfs to overwrite
145 # the one packed into the Live system.
146 if [ -d "/home/boot/rootfs" ]; then
147 cp -a /home/boot/rootfs/* /
148 fi ;;
149 laptop)
150 # Laptop option to load related Kernel modules.
151 echo "Loading laptop modules: ac, battery, fan, yenta_socket..."
152 for mod in ac battery fan yenta_socket
153 do
154 modprobe $mod
155 done
156 grep -qs batt /etc/lxpanel/default/panels/panel ||
157 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
158 /etc/lxpanel/default/panels/panel 2> /dev/null
159 # Enable Kernel Laptop mode.
160 echo "5" > /proc/sys/vm/laptop_mode ;;
161 mount)
162 # Mount all ext3 partitions found (opt: mount).
163 # Get the list of partitions.
164 DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'`
165 # Mount filesystems rw.
166 for device in $DEVICES_LIST
167 do
168 name=${device#/dev/}
169 # Device can be already used by home=usb.
170 if ! mount | grep ^$device >/dev/null; then
171 echo "Mounting partition: $name on /mnt/$name"
172 mkdir /mnt/$name
173 mount $device /mnt/$name
174 fi
175 done ;;
176 mount-packages)
177 # Mount and install packages-XXX.iso (useful without Internet
178 # connection).
179 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
180 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
181 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
182 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
183 if [ -n "$PKGDEV" ]; then
184 echo -n "Mounting packages archive from $PKGDEV..."
185 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
186 status
187 /packages/install.sh
188 fi ;;
189 wm=*)
190 # Check for a Window Manager (for a flavor, default WM can be changed
191 # with boot options or with an addfile in /etc/X11/wm.default.
192 WM=${opt#wm=}
193 mkdir -p /etc/X11
194 case $WM in
195 jwm)
196 echo "jwm" > /etc/X11/wm.default ;;
197 ob|openbox|openbox-session)
198 echo "openbox" > /etc/X11/wm.default ;;
199 e17|enlightenment|enlightenment_start)
200 echo "enlightenment" > /etc/X11/wm.default ;;
201 esac ;;
202 *)
203 continue ;;
204 esac
205 done
207 # If no default WM fallback to Openbox (we never know).
208 if [ ! -f /etc/X11/wm.default ]; then
209 echo "openbox" > /etc/X11/wm.default
210 fi
212 # Activate an eventual swap file or partition.
213 if [ "`fdisk -l | grep swap`" ]; then
214 for SWAP_DEV in `fdisk -l | sed '/swap/!d;s/ .*//'`; do
215 echo "Swap memory detected on: $SWAP_DEV"
216 add_swap_in_fstab $SWAP_DEV
217 done
218 fi
219 if grep -q swap /etc/fstab; then
220 echo "Activating swap memory..."
221 swapon -a
222 fi