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

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