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

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