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

bootopts.sh+rcS: Fix typo
author Christophe Lincoln <pankso@slitaz.org>
date Sun Apr 26 16:31:46 2009 +0200 (2009-04-26)
parents 30b287d766bf
children c2bc39dc7985
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 #
33 mount_home()
34 {
35 echo "Home has been specified to $DEVICE..."
36 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
37 USBDELAY=$((1+$USBDELAY))
38 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
39 sleep $USBDELAY
40 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
41 DEVID=$DEVICE
42 if [ -x /sbin/blkid ]; then
43 # Can be label, uuid or devname. DEVID give us first: /dev/name.
44 DEVID=`/sbin/blkid | grep $DEVICE | cut -d: -f1`
45 DEVID=${DEVID##*/}
46 fi
47 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
48 echo "Mounting /home on /dev/$DEVID... "
49 mv /home/$USER /tmp/$USER-files
50 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
51 || mount /dev/$DEVID /home
52 gen_home_swap
53 else
54 echo "Unable to find $DEVICE... "
55 fi
56 # Move all hacker dir if needed.
57 if [ ! -d "/home/$USER" ] ; then
58 mv /tmp/$USER-files /home/$USER
59 chown -R $USER.$USER /home/$USER
60 else
61 rm -rf /tmp/$USER-files
62 fi
63 }
65 # Default user account without password (uid=1000). In live mode the option
66 # user=name can be used, but user must be add before home= to have home dir.
67 if ! grep -q "1000:1000" /etc/passwd; then
68 if grep -q "user=" /proc/cmdline; then
69 USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
70 # Avoid usage of an existing system user or root.
71 if grep -q ^$USER /etc/passwd; then
72 USER=tux
73 fi
74 else
75 USER=tux
76 fi
77 echo -n "Configuring user and group: $USER..."
78 echo "$USER:x:1000:1000:SliTaz User,,,:/home/$USER:/bin/sh" >> /etc/passwd
79 echo "$USER::14035:0:99999:7:::" >> /etc/shadow
80 echo "$USER:x:1000:" >> /etc/group
81 echo "$USER:!::" >> /etc/gshadow
82 status
83 # Audio group.
84 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
85 # /home/$USER files from /etc/skel.
86 if [ -d /etc/skel ]; then
87 cp -a /etc/skel /home/$USER
88 # Path for user desktop files.
89 for i in /home/$USER/.local/share/applications/*.desktop
90 do
91 sed -i s/"user_name"/"$USER"/g $i
92 done
93 else
94 mkdir -p /home/$USER
95 fi
96 # set permissions.
97 chown -R $USER.$USER /home/$USER
98 # Slim default user.
99 if [ -f /etc/slim.conf ]; then
100 sed -i s/"default_user .*"/"default_user $USER"/\
101 /etc/slim.conf
102 fi
103 fi
105 # Parse /proc/cmdline for boot options.
106 echo "Parsing kernel cmdline for SliTaz live options... "
107 for opt in `cat /proc/cmdline`
108 do
109 case $opt in
110 eject)
111 # Eject cdrom.
112 eject /dev/cdrom ;;
113 autologin)
114 # Autologin option to skip first graphic login prompt.
115 echo "auto_login yes" >> /etc/slim.conf ;;
116 home=usb)
117 # home=usb is a shoter and easy way to have home=/dev/sda1.
118 DEVICE=sda1
119 mount_home ;;
120 home=*)
121 # Check for a specified home directory (home=*).
122 DEVICE=${opt#home=}
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, yenta_socket..."
140 modprobe ac
141 modprobe battery
142 modprobe yenta_socket ;;
143 mount)
144 # Mount all ext3 partitions found (opt: mount).
145 # Get the list of partitions.
146 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
147 # Mount filesystems rw.
148 for device in $DEVICES_LIST
149 do
150 name=${device#/dev/}
151 # Device can be already used by home=usb.
152 if ! mount | grep ^$device >/dev/null; then
153 echo "Mounting partition: $name on /mnt/$name"
154 mkdir /mnt/$name
155 mount $device /mnt/$name
156 fi
157 done ;;
158 mount-packages)
159 # Mount and install packages-XXX.iso (usefull without Internet
160 # connection).
161 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
162 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
163 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
164 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
165 if [ -n "$PKGDEV" ]; then
166 echo -n "Mounting packages archive from $PKGDEV..."
167 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
168 status
169 /packages/install.sh
170 fi ;;
171 wm=*)
172 # Check for a Window Manager (for a flavor, default WM can be changed
173 # with boot option or with an addfile in /etc/X11/wm.default.
174 WM=${opt#wm=}
175 mkdir -p /etc/X11
176 case $WM in
177 jwm)
178 echo "jwm" > /etc/X11/wm.default ;;
179 ob|openbox|openbox-session)
180 echo "openbox" > /etc/X11/wm.default ;;
181 e17|enlightenment|enlightenment_start)
182 echo "enlightenment" > /etc/X11/wm.default ;;
183 esac ;;
184 *)
185 continue ;;
186 esac
187 done
189 # If no default WM fallback to Openbox (we never know).
190 if [ ! -f /etc/X11/wm.default ]; then
191 echo "openbox" > /etc/X11/wm.default
192 fi
194 # Activate an eventual swap file or partition.
195 if [ "`fdisk -l | grep swap`" ]; then
196 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
197 echo "Swap memory detected on: $SWAP_DEV"
198 add_swap_in_fstab $SWAP_DEV
199 done
200 fi
201 if grep -q swap /etc/fstab; then
202 echo "Activating swap memory..."
203 swapon -a
204 fi