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

etc/init.d/{bootopts.sh,network.sh,rcS}: follow changes in the libtaz.sh for i18n functions.
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon Jan 09 02:20:10 2017 +0200 (2017-01-09)
parents ae63069a080f
children a25d6905c56f
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 fgrep -q 'user=' /proc/cmdline; then
26 USER=$(cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/')
27 # Avoid usage of an existing system user or root.
28 if grep -q ^$USER /etc/passwd; then
29 USER=tux
30 fi
31 else
32 USER=tux
33 fi
35 if ! grep -q '100[0-9]:100' /etc/passwd; then
36 # Make sure we have users applications.conf
37 if [ ! -f '/etc/skel/.config/slitaz/applications.conf' -a \
38 -f '/etc/slitaz/applications.conf' ]; then
39 mkdir -p /etc/skel/.config/slitaz
40 cp /etc/slitaz/applications.conf /etc/skel/.config/slitaz
41 fi
43 action 'Configuring user and group: %s...' "$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; do
47 addgroup $USER $group
48 done
49 status
51 # Slim default user
52 if [ -f /etc/slim.conf ]; then
53 sed -i "s|default_user .*|default_user $USER|" /etc/slim.conf
54 fi
55 fi
57 # Make sure selected user has home
58 if [ ! -d /home/$USER ]; then
59 cp -a /etc/skel /home/$USER
60 chown -R $USER:users /home/$USER
61 fi
63 for opt in $(cat /proc/cmdline); 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 if [ -f /etc/slim.conf ]; then
71 sed -i '/auto_login .*/d' /etc/slim.conf
72 echo 'auto_login yes' >> /etc/slim.conf
73 fi ;;
74 lang=*)
75 # Check for a specified locale (lang=*).
76 LANG=${opt#lang=}
77 /sbin/tazlocale ${LANG%.UTF-8} ;;
78 kmap=*)
79 # Check for a specified keymap (kmap=*).
80 KEYMAP=${opt#kmap=}
81 action 'Setting system keymap to: %s...' "$KEYMAP"
82 echo "$KEYMAP" > /etc/keymap.conf
83 status ;;
84 font=*)
85 # Check for a specified console font (font=*).
86 FONT=${opt#font=}
87 action 'Setting console font to: %s...' "$FONT"
88 for con in 1 2 3 4 5 6; do
89 setfont $FONT -C /dev/tty$con
90 done
91 status ;;
92 home=*)
93 # Check for a specified home partition (home=*) and check for
94 # user home dir. Note: home=usb is a shorter and easier way to
95 # have home=/dev/sda1.
96 DEVICE=${opt#home=}
97 [ "$DEVICE" = "usb" ] && DEVICE="$(usb_device)1"
98 echo "Home has been specified to $DEVICE..."
100 DEVID=$(/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q')
101 if [ -z "$DEVID" ]; then
102 USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
103 USBDELAY=$((2+$USBDELAY))
104 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
105 sleep $USBDELAY
106 fi
108 USER=$(cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q')
109 DEVID=$DEVICE
110 if [ -x /sbin/blkid ]; then
111 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
112 DEVID=$(/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q')
113 fi
114 DEVID=${DEVID##*/}
116 if [ -n "$DEVID" ] && fgrep -q "$DEVID" /proc/partitions ; then
117 echo "Mounting /home on /dev/$DEVID... "
118 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
119 mount /dev/$DEVID /home &&
120 case "$(/sbin/blkid | grep /dev/$DEVID:)" in
121 *\"ntfs\"*|*\"vfat\"*)
122 mount.posixovl -F /home -- -oallow_other -odefault_permissions -osuid ;;
123 esac
124 mount /home -o remount,uid=1000,gid=100 2>/dev/null
126 # Check if swap file must be generated in /home: swap=size (Mb).
127 # This option is only used within home=device.
128 if grep -q 'swap=[1-9]*' /proc/cmdline; then
129 SWAP_SIZE=$(sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline)
130 # DD to gen a virtual disk.
131 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
132 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
133 # Make the Linux swap filesystem.
134 mkswap /home/swap
135 add_swap_in_fstab /home/swap
136 fi
137 else
138 echo "Unable to find $DEVICE... "
139 fi
141 # Move all user dir if needed.
142 if [ ! -d "/home/$USER" ] ; then
143 mv /tmp/$USER-files /home/$USER
144 chown -R $USER.users /home/$USER
145 else
146 rm -rf /tmp/$USER-files
147 fi
149 # Install all packages in /home/boot/packages. In live CD and
150 # USB mode the option home= mounts the device on /home, so we
151 # already have a boot directory with the Kernel and rootfs.
152 if [ -d '/home/boot/packages' ]; then
153 for pkg in /home/boot/packages/*.tazpkg; do
154 tazpkg install $pkg
155 done
156 fi
158 # We can have custom files in /home/boot/rootfs to overwrite
159 # the one packed into the Live system.
160 if [ -d '/home/boot/rootfs' ]; then
161 cp -a /home/boot/rootfs/* /
162 fi ;;
163 laptop)
164 # Enable Kernel Laptop mode.
165 echo '5' > /proc/sys/vm/laptop_mode ;;
166 mount)
167 # Mount all ext3 partitions found (opt: mount).
169 # Get the list of partitions.
170 DEVICES_LIST=$(fdisk -l | sed '/83 Linux/!d;s/ .*//')
172 # Mount filesystems rw.
173 for device in $DEVICES_LIST; do
174 name=${device#/dev/}
175 # Device can be already used by home=usb.
176 if ! mount | grep ^$device >/dev/null; then
177 echo "Mounting partition: $name on /mnt/$name"
178 mkdir -p /mnt/$name
179 mount $device /mnt/$name
180 fi
181 done ;;
182 mount-packages)
183 # Mount and install packages-XXX.iso (useful without Internet
184 # connection).
185 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
186 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
187 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
188 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
189 if [ -n "$PKGDEV" ]; then
190 action 'Mounting packages archive from %s...' "$PKGDEV"
191 mkdir -p /packages; mount -t iso9660 -o ro $PKGDEV /packages
192 status
193 /packages/install.sh
194 fi ;;
195 wm=*)
196 # Check for a Window Manager (for a flavor, default WM can be changed
197 # with boot options or via /etc/slitaz/applications.conf).
198 WM=${opt#wm=}
199 case $WM in
200 ob|openbox|openbox-session)
201 WM=openbox-session ;;
202 e17|enlightenment|enlightenment_start)
203 WM=enlightenment ;;
204 razorqt|razor-session)
205 WM=razor-session ;;
206 esac
207 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
208 /etc/slitaz/applications.conf ;;
209 *)
210 continue ;;
211 esac
212 done