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

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