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

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