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

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