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

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