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

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