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

Use adduser in bootopts.sh script since it adduser copys /etc/skel again. USER will be added to users group now instead of USER group. I also chmod the /home/USER folder to 700 so no one but the user in question can read it.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun Mar 06 16:21:42 2011 +0000 (2011-03-06)
parents f12a7bdb3980
children 07c1d9c8ac36 68435a9c0843
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 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER
32 status
33 # Audio and cdrom group.
34 addgroup $USER audio
35 addgroup $USER cdrom
36 addgroup $USER video
37 addgroup $USER tty
38 # /home/$USER files from /etc/skel.
39 if [ -d /home/$USER ]; then
40 # Path for user desktop files.
41 for i in /home/$USER/.local/share/applications/*.desktop
42 do
43 sed -i s/"user_name"/"$USER"/g $i
44 done
45 else
46 mkdir -p /home/$USER
47 fi
48 # make user be only read/write by user
49 chmod -R 700 /home/$USER
50 # Slim default user.
51 if [ -f /etc/slim.conf ]; then
52 sed -i s/"default_user .*"/"default_user $USER"/\
53 /etc/slim.conf
54 fi
55 fi
57 # Parse /proc/cmdline for boot options.
58 echo "Parsing kernel cmdline for SliTaz live options... "
60 for opt in `cat /proc/cmdline`
61 do
62 case $opt in
63 eject)
64 # Eject cdrom.
65 eject /dev/cdrom ;;
66 autologin)
67 # Autologin option to skip first graphic login prompt.
68 echo "auto_login yes" >> /etc/slim.conf ;;
69 lang=*)
70 # Check for a specified locale (lang=*).
71 LANG=${opt#lang=}
72 echo -n "Setting system locale to: $LANG... "
73 echo "LANG=$LANG" > /etc/locale.conf
74 echo "LC_ALL=$LANG" >> /etc/locale.conf
75 [ ! -d /usr/lib/locale/$LANG ] && localedef \
76 -i $LANG -c -f UTF-8 /usr/lib/locale/$LANG &
77 tazlocale link-files
78 status ;;
79 kmap=*)
80 # Check for a specified keymap (kmap=*).
81 KEYMAP=${opt#kmap=}
82 echo -n "Setting system keymap to: $KEYMAP..."
83 echo "$KEYMAP" > /etc/keymap.conf
84 status ;;
85 home=*)
86 # Check for a specified home partition (home=*) and check for
87 # user home dir. Note: home=usb is a shorter and easier way to
88 # have home=/dev/sda1.
89 DEVICE=${opt#home=}
90 [ "$DEVICE" = "usb" ] && DEVICE=sda1
91 echo "Home has been specified to $DEVICE..."
92 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
93 if [ -z "$DEVID" ]; then
94 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
95 USBDELAY=$((2+$USBDELAY))
96 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
97 sleep $USBDELAY
98 fi
99 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
100 DEVID=$DEVICE
101 if [ -x /sbin/blkid ]; then
102 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
103 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
104 fi
105 DEVID=${DEVID##*/}
106 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
107 echo "Mounting /home on /dev/$DEVID... "
108 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
109 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
110 || mount /dev/$DEVID /home
111 # Check if swap file must be generated in /home: swap=size (Mb).
112 # This option is only used within home=device.
113 if grep -q "swap=[1-9]*" /proc/cmdline; then
114 SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
115 # DD to gen a virtual disk.
116 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
117 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
118 # Make the Linux swap filesystem.
119 mkswap /home/swap
120 add_swap_in_fstab /home/swap
121 fi
122 else
123 echo "Unable to find $DEVICE... "
124 fi
125 # Move all user dir if needed.
126 if [ ! -d "/home/$USER" ] ; then
127 mv /tmp/$USER-files /home/$USER
128 chown -R $USER.users /home/$USER
129 else
130 rm -rf /tmp/$USER-files
131 fi
132 # Install all packages in /home/boot/packages. In live CD and
133 # USB mode the option home= mounts the device on /home, so we
134 # already have a boot directory with the Kernel and rootfs.
135 if [ -d "/home/boot/packages" ]; then
136 for pkg in /home/boot/packages/*.tazpkg
137 do
138 tazpkg install $pkg
139 done
140 fi
141 # We can have custom files in /home/boot/rootfs to overwrite
142 # the one packed into the Live system.
143 if [ -d "/home/boot/rootfs" ]; then
144 cp -a /home/boot/rootfs/* /
145 fi ;;
146 laptop)
147 # Laptop option to load related Kernel modules.
148 echo "Loading laptop modules: ac, battery, fan, yenta_socket..."
149 for mod in ac battery fan yenta_socket
150 do
151 modprobe $mod
152 done
153 grep -qs batt /etc/lxpanel/default/panels/panel ||
154 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
155 /etc/lxpanel/default/panels/panel 2> /dev/null
156 # Enable Kernel Laptop mode.
157 echo "5" > /proc/sys/vm/laptop_mode ;;
158 mount)
159 # Mount all ext3 partitions found (opt: mount).
160 # Get the list of partitions.
161 DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'`
162 # Mount filesystems rw.
163 for device in $DEVICES_LIST
164 do
165 name=${device#/dev/}
166 # Device can be already used by home=usb.
167 if ! mount | grep ^$device >/dev/null; then
168 echo "Mounting partition: $name on /mnt/$name"
169 mkdir /mnt/$name
170 mount $device /mnt/$name
171 fi
172 done ;;
173 mount-packages)
174 # Mount and install packages-XXX.iso (useful without Internet
175 # connection).
176 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
177 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
178 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
179 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
180 if [ -n "$PKGDEV" ]; then
181 echo -n "Mounting packages archive from $PKGDEV..."
182 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
183 status
184 /packages/install.sh
185 fi ;;
186 wm=*)
187 # Check for a Window Manager (for a flavor, default WM can be changed
188 # with boot options or with an addfile in /etc/X11/wm.default.
189 WM=${opt#wm=}
190 mkdir -p /etc/X11
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 *)
200 continue ;;
201 esac
202 done
204 # If no default WM fallback to Openbox (we never know).
205 if [ ! -f /etc/X11/wm.default ]; then
206 echo "openbox" > /etc/X11/wm.default
207 fi
209 # Activate an eventual swap file or partition.
210 if [ "`fdisk -l | grep swap`" ]; then
211 for SWAP_DEV in `fdisk -l | sed '/swap/!d;s/ .*//'`; do
212 echo "Swap memory detected on: $SWAP_DEV"
213 add_swap_in_fstab $SWAP_DEV
214 done
215 fi
216 if grep -q swap /etc/fstab; then
217 echo "Activating swap memory..."
218 swapon -a
219 fi