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

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