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

Fix: home= user dir may already be moved (writfs)
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 21 01:29:38 2010 +0100 (2010-03-21)
parents fcb91755f5fc
children ac912393ff1c
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 [ ! -d /usr/lib/locale/$LANG ] && localedef \
78 -i $LANG -c -f UTF-8 /usr/lib/locale/$LANG &
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 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
94 USBDELAY=$((1+$USBDELAY))
95 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
96 sleep $USBDELAY
97 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
98 DEVID=$DEVICE
99 if [ -x /sbin/blkid ]; then
100 # Can be a label, uuid or devname. DEVID gives us first: /dev/name.
101 DEVID=`/sbin/blkid | grep $DEVICE | cut -d: -f1`
102 DEVID=${DEVID##*/}
103 fi
104 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
105 echo "Mounting /home on /dev/$DEVID... "
106 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
107 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
108 || mount /dev/$DEVID /home
109 # Check if swap file must be generated in /home: swap=size (Mb).
110 # This option is only used within home=device.
111 if grep -q "swap=[1-9]*" /proc/cmdline; then
112 SWAP_SIZE=`cat /proc/cmdline | sed 's/.*swap=\([^ ]*\).*/\1/'`
113 # DD to gen a virtual disk.
114 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
115 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
116 # Make the Linux swap filesystem.
117 mkswap /home/swap
118 add_swap_in_fstab /home/swap
119 fi
120 else
121 echo "Unable to find $DEVICE... "
122 fi
123 # Move all user dir if needed.
124 if [ ! -d "/home/$USER" ] ; then
125 mv /tmp/$USER-files /home/$USER
126 chown -R $USER.$USER /home/$USER
127 else
128 rm -rf /tmp/$USER-files
129 fi
130 # Install all packages in /home/boot/packages. In live CD and
131 # USB mode the option home= mounts the device on /home, so we
132 # already have a boot directory with the Kernel and rootfs.
133 if [ -d "/home/boot/packages" ]; then
134 for pkg in /home/boot/packages/*.tazpkg
135 do
136 tazpkg install $pkg
137 done
138 fi ;;
139 laptop)
140 # Laptop option to load related Kernel modules.
141 echo "Loading laptop modules: ac, battery, fan, yenta_socket..."
142 for mod in ac battery fan yenta_socket
143 do
144 modprobe $mod
145 done
146 grep -qs batt /etc/lxpanel/default/panels/panel ||
147 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
148 /etc/lxpanel/default/panels/panel 2> /dev/null
149 # Enable Kernel Laptop mode.
150 echo "5" > /proc/sys/vm/laptop_mode ;;
151 mount)
152 # Mount all ext3 partitions found (opt: mount).
153 # Get the list of partitions.
154 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
155 # Mount filesystems rw.
156 for device in $DEVICES_LIST
157 do
158 name=${device#/dev/}
159 # Device can be already used by home=usb.
160 if ! mount | grep ^$device >/dev/null; then
161 echo "Mounting partition: $name on /mnt/$name"
162 mkdir /mnt/$name
163 mount $device /mnt/$name
164 fi
165 done ;;
166 mount-packages)
167 # Mount and install packages-XXX.iso (useful without Internet
168 # connection).
169 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
170 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
171 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
172 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
173 if [ -n "$PKGDEV" ]; then
174 echo -n "Mounting packages archive from $PKGDEV..."
175 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
176 status
177 /packages/install.sh
178 fi ;;
179 wm=*)
180 # Check for a Window Manager (for a flavor, default WM can be changed
181 # with boot options or with an addfile in /etc/X11/wm.default.
182 WM=${opt#wm=}
183 mkdir -p /etc/X11
184 case $WM in
185 jwm)
186 echo "jwm" > /etc/X11/wm.default ;;
187 ob|openbox|openbox-session)
188 echo "openbox" > /etc/X11/wm.default ;;
189 e17|enlightenment|enlightenment_start)
190 echo "enlightenment" > /etc/X11/wm.default ;;
191 esac ;;
192 *)
193 continue ;;
194 esac
195 done
197 # If no default WM fallback to Openbox (we never know).
198 if [ ! -f /etc/X11/wm.default ]; then
199 echo "openbox" > /etc/X11/wm.default
200 fi
202 # Activate an eventual swap file or partition.
203 if [ "`fdisk -l | grep swap`" ]; then
204 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
205 echo "Swap memory detected on: $SWAP_DEV"
206 add_swap_in_fstab $SWAP_DEV
207 done
208 fi
209 if grep -q swap /etc/fstab; then
210 echo "Activating swap memory..."
211 swapon -a
212 fi