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

bootopts.sh: fix posixovl args
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Mar 26 20:34:53 2014 +0000 (2014-03-26)
parents 86ae53480b99
children 3671428835e5
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
26 if fgrep -q "user=" /proc/cmdline; then
27 USER=$(cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/')
28 # Avoid usage of an existing system user or root.
29 if grep -q ^$USER /etc/passwd; then
30 USER=tux
31 fi
32 else
33 USER=tux
34 fi
35 echo -n "Configuring user and group: $USER..."
36 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER
37 passwd -d $USER >/dev/null
38 status
39 # Audio and cdrom group.
40 addgroup $USER audio
41 addgroup $USER cdrom
42 addgroup $USER video
43 addgroup $USER tty
44 # Slim default user.
45 if [ -f /etc/slim.conf ]; then
46 sed -i s/"default_user .*"/"default_user $USER"/\
47 /etc/slim.conf
48 fi
49 fi
51 for opt in $(cat /proc/cmdline)
52 do
53 case $opt in
54 eject)
55 # Eject cdrom.
56 eject /dev/cdrom ;;
57 autologin)
58 # Autologin option to skip first graphic login prompt.
59 echo "auto_login yes" >> /etc/slim.conf ;;
60 lang=*)
61 # Check for a specified locale (lang=*).
62 LANG=${opt#lang=}
63 /sbin/tazlocale $LANG ;;
64 kmap=*)
65 # Check for a specified keymap (kmap=*).
66 KEYMAP=${opt#kmap=}
67 echo -n "Setting system keymap to: $KEYMAP..."
68 echo "$KEYMAP" > /etc/keymap.conf
69 status ;;
70 home=*)
71 # Check for a specified home partition (home=*) and check for
72 # user home dir. Note: home=usb is a shorter and easier way to
73 # have home=/dev/sda1.
74 DEVICE=${opt#home=}
75 [ "$DEVICE" = "usb" ] && DEVICE="$(usb_device)1"
76 echo "Home has been specified to $DEVICE..."
77 DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'`
78 if [ -z "$DEVID" ]; then
79 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
80 USBDELAY=$((2+$USBDELAY))
81 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
82 sleep $USBDELAY
83 fi
84 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
85 DEVID=$DEVICE
86 if [ -x /sbin/blkid ]; then
87 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
88 DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'`
89 fi
90 DEVID=${DEVID##*/}
91 if [ -n "$DEVID" ] && fgrep -q "$DEVID" /proc/partitions ; then
92 echo "Mounting /home on /dev/$DEVID... "
93 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
94 mount /dev/$DEVID /home &&
95 case "$(/sbin/blkid | grep /dev/$DEVID:)" in
96 *\"ntfs\"*|*\"vfat\"*) mount.posixovl -F /home -- -oallow_other -odefault_permissions -osuid ;;
97 esac
98 mount /home -o remount,uid=1000,gid=100 2>/dev/null
99 # Check if swap file must be generated in /home: swap=size (Mb).
100 # This option is only used within home=device.
101 if grep -q "swap=[1-9]*" /proc/cmdline; then
102 SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
103 # DD to gen a virtual disk.
104 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
105 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
106 # Make the Linux swap filesystem.
107 mkswap /home/swap
108 add_swap_in_fstab /home/swap
109 fi
110 else
111 echo "Unable to find $DEVICE... "
112 fi
113 # Move all user dir if needed.
114 if [ ! -d "/home/$USER" ] ; then
115 mv /tmp/$USER-files /home/$USER
116 chown -R $USER.users /home/$USER
117 else
118 rm -rf /tmp/$USER-files
119 fi
120 # Install all packages in /home/boot/packages. In live CD and
121 # USB mode the option home= mounts the device on /home, so we
122 # already have a boot directory with the Kernel and rootfs.
123 if [ -d "/home/boot/packages" ]; then
124 for pkg in /home/boot/packages/*.tazpkg
125 do
126 tazpkg install $pkg
127 done
128 fi
129 # We can have custom files in /home/boot/rootfs to overwrite
130 # the one packed into the Live system.
131 if [ -d "/home/boot/rootfs" ]; then
132 cp -a /home/boot/rootfs/* /
133 fi ;;
134 laptop)
135 # Enable Kernel Laptop mode.
136 echo "5" > /proc/sys/vm/laptop_mode ;;
137 mount)
138 # Mount all ext3 partitions found (opt: mount).
139 # Get the list of partitions.
140 DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'`
141 # Mount filesystems rw.
142 for device in $DEVICES_LIST
143 do
144 name=${device#/dev/}
145 # Device can be already used by home=usb.
146 if ! mount | grep ^$device >/dev/null; then
147 echo "Mounting partition: $name on /mnt/$name"
148 mkdir /mnt/$name
149 mount $device /mnt/$name
150 fi
151 done ;;
152 mount-packages)
153 # Mount and install packages-XXX.iso (useful without Internet
154 # connection).
155 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
156 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
157 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
158 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
159 if [ -n "$PKGDEV" ]; then
160 echo -n "Mounting packages archive from $PKGDEV..."
161 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
162 status
163 /packages/install.sh
164 fi ;;
165 wm=*)
166 # Check for a Window Manager (for a flavor, default WM can be changed
167 # with boot options or via /etc/slitaz/applications.conf).
168 WM=${opt#wm=}
169 case $WM in
170 ob|openbox|openbox-session)
171 WM=openbox-session ;;
172 e17|enlightenment|enlightenment_start)
173 WM=enlightenment ;;
174 razorqt|razor-session)
175 WM=razor-session ;;
176 esac
177 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
178 /etc/slitaz/applications.conf ;;
179 *)
180 continue ;;
181 esac
182 done
184 # If no default WM fallback to Openbox (we never know).
185 if [ ! -f /etc/X11/wm.default ]; then
186 echo "openbox" > /etc/X11/wm.default
187 fi