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

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