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

Add user to disk group... we never know!
author Christophe Lincoln <pankso@slitaz.org>
date Mon May 05 22:02:43 2014 +0200 (2014-05-05)
parents b0b8423150c4
children 6a2336e84fa6
line source
1 #!/bin/sh
2 #
3 # /etc/init.d/bootopts.sh : SliTaz boot options from the cmdline
4 #
5 # Earlier boot options are in rcS, ex: config= and modprobe=
6 #
7 . /etc/init.d/rc.functions
9 # Get first usb disk
10 usb_device() {
11 cd /sys/block
12 for i in sd* sda ; do
13 grep -qs 1 $i/removable && break
14 done
15 echo $i
16 }
18 # Parse /proc/cmdline for boot options.
19 echo "Checking for SliTaz cmdline options..."
21 # Default user account without password (uid=1000). In live mode the option
22 # user=name can be used, but user must be added before home= to have home dir.
23 # This option is not handled by a loop and case like others and has no
24 # effect on an installed system.
25 if ! grep -q "100[0-9]:100" /etc/passwd; then
27 if fgrep -q "user=" /proc/cmdline; then
28 USER=$(cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/')
29 # Avoid usage of an existing system user or root.
30 if grep -q ^$USER /etc/passwd; then
31 USER=tux
32 fi
33 else
34 USER=tux
35 fi
37 # Make sure we have users applications.conf
38 if [ ! -f "/etc/skel/.config/slitaz/applications.conf" ]; then
39 mkdir -p /etc/skel/.config/slitaz
40 cp /etc/slitaz/applications.conf /etc/skel/.config/slitaz
41 fi
43 echo -n "Configuring user and group: $USER..."
44 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER
45 passwd -d $USER >/dev/null
46 for group in audio cdrom video tty plugdev disk
47 do
48 addgroup $USER ${group}
49 done
50 status
52 # Slim default user
53 if [ -f /etc/slim.conf ]; then
54 sed -i s/"default_user .*"/"default_user $USER"/ /etc/slim.conf
55 fi
56 fi
58 for opt in $(cat /proc/cmdline)
59 do
60 case $opt in
61 eject)
62 # Eject cdrom.
63 eject /dev/cdrom ;;
64 autologin)
65 # Autologin option to skip first graphic login prompt.
66 echo "auto_login yes" >> /etc/slim.conf ;;
67 lang=*)
68 # Check for a specified locale (lang=*).
69 LANG=${opt#lang=}
70 /sbin/tazlocale $LANG ;;
71 kmap=*)
72 # Check for a specified keymap (kmap=*).
73 KEYMAP=${opt#kmap=}
74 echo -n "Setting system keymap to: $KEYMAP..."
75 echo "$KEYMAP" > /etc/keymap.conf
76 status ;;
77 home=*)
78 # Check for a specified home partition (home=*) and check for
79 # user home dir. Note: home=usb is a shorter and easier way to
80 # have home=/dev/sda1.
81 DEVICE=${opt#home=}
82 [ "$DEVICE" = "usb" ] && DEVICE="$(usb_device)1"
83 echo "Home has been specified to $DEVICE..."
84 DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'`
85 if [ -z "$DEVID" ]; then
86 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
87 USBDELAY=$((2+$USBDELAY))
88 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
89 sleep $USBDELAY
90 fi
91 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
92 DEVID=$DEVICE
93 if [ -x /sbin/blkid ]; then
94 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
95 DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'`
96 fi
97 DEVID=${DEVID##*/}
98 if [ -n "$DEVID" ] && fgrep -q "$DEVID" /proc/partitions ; then
99 echo "Mounting /home on /dev/$DEVID... "
100 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
101 mount /dev/$DEVID /home &&
102 case "$(/sbin/blkid | grep /dev/$DEVID:)" in
103 *\"ntfs\"*|*\"vfat\"*) mount.posixovl -F /home -- -oallow_other -odefault_permissions -osuid ;;
104 esac
105 mount /home -o remount,uid=1000,gid=100 2>/dev/null
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=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
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.users /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 # We can have custom files in /home/boot/rootfs to overwrite
137 # the one packed into the Live system.
138 if [ -d "/home/boot/rootfs" ]; then
139 cp -a /home/boot/rootfs/* /
140 fi ;;
141 laptop)
142 # Enable Kernel Laptop mode.
143 echo "5" > /proc/sys/vm/laptop_mode ;;
144 mount)
145 # Mount all ext3 partitions found (opt: mount).
146 # Get the list of partitions.
147 DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'`
148 # Mount filesystems rw.
149 for device in $DEVICES_LIST
150 do
151 name=${device#/dev/}
152 # Device can be already used by home=usb.
153 if ! mount | grep ^$device >/dev/null; then
154 echo "Mounting partition: $name on /mnt/$name"
155 mkdir /mnt/$name
156 mount $device /mnt/$name
157 fi
158 done ;;
159 mount-packages)
160 # Mount and install packages-XXX.iso (useful without Internet
161 # connection).
162 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
163 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
164 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
165 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
166 if [ -n "$PKGDEV" ]; then
167 echo -n "Mounting packages archive from $PKGDEV..."
168 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
169 status
170 /packages/install.sh
171 fi ;;
172 wm=*)
173 # Check for a Window Manager (for a flavor, default WM can be changed
174 # with boot options or via /etc/slitaz/applications.conf).
175 WM=${opt#wm=}
176 case $WM in
177 ob|openbox|openbox-session)
178 WM=openbox-session ;;
179 e17|enlightenment|enlightenment_start)
180 WM=enlightenment ;;
181 razorqt|razor-session)
182 WM=razor-session ;;
183 esac
184 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
185 /etc/slitaz/applications.conf ;;
186 *)
187 continue ;;
188 esac
189 done