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

Improve and tidy scripts, start tazhw from rcS and start network.sh earlier
author Christophe Lincoln <pankso@slitaz.org>
date Tue Apr 21 01:46:21 2009 +0200 (2009-04-21)
parents deb719ede74f
children 965cc9d8722a
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: 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 echo "Sleeping 10 s to let the kernel detect the device... "
37 sleep 10
38 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
39 DEVID=$DEVICE
40 if [ -x /sbin/blkid ]; then
41 # Can be label, uuid or devname. DEVID give us first: /dev/name.
42 DEVID=`/sbin/blkid | grep $DEVICE | cut -d: -f1`
43 DEVID=${DEVID##*/}
44 fi
45 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
46 echo "Mounting /home on /dev/$DEVID... "
47 mv /home/$USER /tmp/$USER-files
48 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
49 || mount /dev/$DEVID /home
50 gen_home_swap
51 else
52 echo "Unable to find $DEVICE... "
53 fi
54 # Move all hacker dir if needed.
55 if [ ! -d "/home/$USER" ] ; then
56 mv /tmp/$USER-files /home/$USER
57 chown -R $USER.$USER /home/$USER
58 else
59 rm -rf /tmp/$USER-files
60 fi
61 }
63 # Mount all ext3 partitions found (opt: mount).
64 mount_partitions()
65 {
66 # Get the list of partitions.
67 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
68 # Mount filesystems rw.
69 for device in $DEVICES_LIST
70 do
71 name=${device#/dev/}
72 # Device can be already used by home=usb.
73 if ! mount | grep ^$device >/dev/null; then
74 echo "Mounting partition: $name on /mnt/$name"
75 mkdir /mnt/$name
76 mount $device /mnt/$name
77 fi
78 done
79 }
81 # Parse /proc/cmdline with grep.
82 #
84 echo "Parsing kernel cmdline for SliTaz live options... "
86 # eject: Eject cdrom
87 if grep -q -w "eject" /proc/cmdline; then
88 eject /dev/cdrom
89 fi
91 # user=name: Default user account without password (uid=1000).
92 #
93 if ! grep -q "1000:1000" /etc/passwd; then
94 if grep -q "user=" /proc/cmdline; then
95 USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
96 # Avoid usage of an existing system user or root.
97 if grep -q ^$USER /etc/passwd; then
98 USER=tux
99 fi
100 else
101 USER=tux
102 fi
103 echo -n "Configuring user and group: $USER..."
104 echo "$USER:x:1000:1000:SliTaz User,,,:/home/$USER:/bin/sh" >> /etc/passwd
105 echo "$USER::14035:0:99999:7:::" >> /etc/shadow
106 echo "$USER:x:1000:" >> /etc/group
107 echo "$USER:!::" >> /etc/gshadow
108 status
109 # Audio group.
110 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
111 # /home/$USER files from /etc/skel.
112 if [ -d /etc/skel ]; then
113 cp -a /etc/skel /home/$USER
114 # Path for user desktop files.
115 for i in /home/$USER/.local/share/applications/*.desktop
116 do
117 sed -i s/"user_name"/"$USER"/g $i
118 done
119 else
120 mkdir -p /home/$USER
121 fi
122 # set permissions.
123 chown -R $USER.$USER /home/$USER
124 # Slim default user.
125 if [ -f /etc/slim.conf ]; then
126 sed -i s/"default_user .*"/"default_user $USER"/\
127 /etc/slim.conf
128 fi
129 fi
131 # Autologin option to skip first graphic login prompt.
132 if grep -q "autologin" /proc/cmdline; then
133 echo "auto_login yes" >> /etc/slim.conf
134 fi
136 # Check for a specified home directory on cmdline (home=*).
137 #
138 if grep -q "home=usb" /proc/cmdline; then
139 DEVICE=sda1
140 mount_home
141 elif grep -q "home=" /proc/cmdline; then
142 DEVICE=`cat /proc/cmdline | sed 's/.*home=\([^ ]*\).*/\1/'`
143 mount_home
144 fi
146 # Activate an eventual swap file in /home and on local HD.
147 #
148 if [ "`fdisk -l | grep swap`" ]; then
149 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
150 echo "Swap memory detected on: $SWAP_DEV"
151 add_swap_in_fstab $SWAP_DEV
152 done
153 fi
154 if grep -q swap /etc/fstab; then
155 echo "Activating swap memory..."
156 swapon -a
157 fi
159 # Check for a specified locale (lang=*).
160 #
161 if grep -q "lang=*" /proc/cmdline; then
162 LANG=`cat /proc/cmdline | sed 's/.*lang=\([^ ]*\).*/\1/'`
163 echo -n "Setting system locale to: $LANG... "
164 echo "LANG=$LANG" > /etc/locale.conf
165 echo "LC_ALL=$LANG" >> /etc/locale.conf
166 status
167 fi
169 # Check for a specified keymap (kmap=*).
170 #
171 if grep -q "kmap=*" /proc/cmdline; then
172 KEYMAP=`cat /proc/cmdline | sed 's/.*kmap=\([^ ]*\).*/\1/'`
173 echo -n "Setting system keymap to: $KEYMAP..."
174 echo "$KEYMAP" > /etc/keymap.conf
175 status
176 fi
178 # Laptop option to load ac and battery Kernel modules.
179 if grep -q "laptop" /proc/cmdline; then
180 echo "Loading laptop modules: ac, battery, yenta_socket..."
181 modprobe ac
182 modprobe battery
183 modprobe yenta_socket
184 fi
186 # Check for a Window Manager (for a flavor, default WM can be changed
187 # with boot option or with an addfile in /etc/X11/wm.default.
188 if grep -q "wm=" /proc/cmdline; then
189 mkdir -p /etc/X11
190 WM=`cat /proc/cmdline | sed 's/.*wm=\([^ ]*\).*/\1/'`
191 case $WM in
192 jwm)
193 echo "jwm" > /etc/X11/wm.default ;;
194 ob|openbox|openbox-session)
195 echo "openbox" > /etc/X11/wm.default ;;
196 e17|enlightenment|enlightenment_start)
197 echo "enlightenment" > /etc/X11/wm.default ;;
198 esac
199 else
200 # If no default WM fallback to Openbox.
201 if [ ! -f /etc/X11/wm.default ]; then
202 echo "openbox" > /etc/X11/wm.default
203 fi
204 fi
206 # Check for option mount.
207 if grep -q "mount" /proc/cmdline; then
208 mount_partitions
209 fi