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

Add condition-option to install packages at boot from /home/boot/packages
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 26 16:55:32 2009 +0200 (2009-04-26)
parents c2bc39dc7985
children cdbc958f594e
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 hacker 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=usb)
119 # home=usb is a shoter and easy way to have home=/dev/sda1.
120 DEVICE=sda1
121 mount_home ;;
122 home=*)
123 # Check for a specified home directory (home=*).
124 DEVICE=${opt#home=}
125 mount_home ;;
126 lang=*)
127 # Check for a specified locale (lang=*).
128 LANG=${opt#lang=}
129 echo -n "Setting system locale to: $LANG... "
130 echo "LANG=$LANG" > /etc/locale.conf
131 echo "LC_ALL=$LANG" >> /etc/locale.conf
132 status ;;
133 kmap=*)
134 # Check for a specified keymap (kmap=*).
135 KEYMAP=${opt#kmap=}
136 echo -n "Setting system keymap to: $KEYMAP..."
137 echo "$KEYMAP" > /etc/keymap.conf
138 status ;;
139 laptop)
140 # Laptop option to load ac and battery 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 mount)
147 # Mount all ext3 partitions found (opt: mount).
148 # Get the list of partitions.
149 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
150 # Mount filesystems rw.
151 for device in $DEVICES_LIST
152 do
153 name=${device#/dev/}
154 # Device can be already used by home=usb.
155 if ! mount | grep ^$device >/dev/null; then
156 echo "Mounting partition: $name on /mnt/$name"
157 mkdir /mnt/$name
158 mount $device /mnt/$name
159 fi
160 done ;;
161 mount-packages)
162 # Mount and install packages-XXX.iso (usefull without Internet
163 # connection).
164 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
165 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
166 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
167 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
168 if [ -n "$PKGDEV" ]; then
169 echo -n "Mounting packages archive from $PKGDEV..."
170 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
171 status
172 /packages/install.sh
173 fi ;;
174 wm=*)
175 # Check for a Window Manager (for a flavor, default WM can be changed
176 # with boot option or with an addfile in /etc/X11/wm.default.
177 WM=${opt#wm=}
178 mkdir -p /etc/X11
179 case $WM in
180 jwm)
181 echo "jwm" > /etc/X11/wm.default ;;
182 ob|openbox|openbox-session)
183 echo "openbox" > /etc/X11/wm.default ;;
184 e17|enlightenment|enlightenment_start)
185 echo "enlightenment" > /etc/X11/wm.default ;;
186 esac ;;
187 *)
188 continue ;;
189 esac
190 done
192 # If no default WM fallback to Openbox (we never know).
193 if [ ! -f /etc/X11/wm.default ]; then
194 echo "openbox" > /etc/X11/wm.default
195 fi
197 # Activate an eventual swap file or partition.
198 if [ "`fdisk -l | grep swap`" ]; then
199 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
200 echo "Swap memory detected on: $SWAP_DEV"
201 add_swap_in_fstab $SWAP_DEV
202 done
203 fi
204 if grep -q swap /etc/fstab; then
205 echo "Activating swap memory..."
206 swapon -a
207 fi
209 # Install all packages in /home/boot/packages. In live (CD and USB) mode
210 # the option home= will mount the device on /home, so we already have
211 # a boot directory with the Kernel and rootfs.
212 if [ -d "/home/boot/packages" ]; then
213 for pkg in /home/boot/packages/*.tazpkg
214 do
215 tazpkg install $pkg
216 done
217 fi