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

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