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

set netbook resolution + batt for laptop
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Nov 09 21:16:17 2009 +0100 (2009-11-09)
parents 16c27ed1f2c9
children aeaaf8796470
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 group.
37 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
38 # /home/$USER files from /etc/skel.
39 if [ -d /etc/skel ]; then
40 cp -a /etc/skel /home/$USER
41 # Path for user desktop files.
42 for i in /home/$USER/.local/share/applications/*.desktop
43 do
44 sed -i s/"user_name"/"$USER"/g $i
45 done
46 else
47 mkdir -p /home/$USER
48 fi
49 # Set permissions.
50 chown -R $USER.$USER /home/$USER
51 # Slim default user.
52 if [ -f /etc/slim.conf ]; then
53 sed -i s/"default_user .*"/"default_user $USER"/\
54 /etc/slim.conf
55 fi
56 fi
58 # Parse /proc/cmdline for boot options.
59 echo "Parsing kernel cmdline for SliTaz live options... "
61 for opt in `cat /proc/cmdline`
62 do
63 case $opt in
64 eject)
65 # Eject cdrom.
66 eject /dev/cdrom ;;
67 autologin)
68 # Autologin option to skip first graphic login prompt.
69 echo "auto_login yes" >> /etc/slim.conf ;;
70 lang=*)
71 # Check for a specified locale (lang=*).
72 LANG=${opt#lang=}
73 echo -n "Setting system locale to: $LANG... "
74 echo "LANG=$LANG" > /etc/locale.conf
75 echo "LC_ALL=$LANG" >> /etc/locale.conf
76 status ;;
77 kmap=*)
78 # Check for a specified keymap (kmap=*).
79 KEYMAP=${opt#kmap=}
80 echo -n "Setting system keymap to: $KEYMAP..."
81 echo "$KEYMAP" > /etc/keymap.conf
82 status ;;
83 home=*)
84 # Check for a specified home partition (home=*) and check for
85 # user home dir. Note: home=usb is a shorter and easier way to
86 # have home=/dev/sda1.
87 DEVICE=${opt#home=}
88 [ "$DEVICE" = "usb" ] && DEVICE=sda1
89 echo "Home has been specified to $DEVICE..."
90 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
91 USBDELAY=$((1+$USBDELAY))
92 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
93 sleep $USBDELAY
94 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
95 DEVID=$DEVICE
96 if [ -x /sbin/blkid ]; then
97 # Can be a label, uuid or devname. DEVID gives us first: /dev/name.
98 DEVID=`/sbin/blkid | grep $DEVICE | cut -d: -f1`
99 DEVID=${DEVID##*/}
100 fi
101 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
102 echo "Mounting /home on /dev/$DEVID... "
103 mv /home/$USER /tmp/$USER-files
104 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
105 || mount /dev/$DEVID /home
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=`cat /proc/cmdline | sed 's/.*swap=\([^ ]*\).*/\1/'`
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.$USER /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 laptop)
137 # Laptop option to load related Kernel modules.
138 echo "Loading laptop modules: ac, battery, fan, yenta_socket..."
139 for mod in ac battery fan yenta_socket
140 do
141 modprobe $mod
142 done
143 grep -qs batt /etc/lxpanel/default/panels/panel ||
144 sed -i 's/= cpu/= batt\n}\n\nPlugin {\n type = cpu/' \
145 /etc/lxpanel/default/panels/panel 2> /dev/null
146 # Enable Kernel Laptop mode.
147 echo "5" > /proc/sys/vm/laptop_mode ;;
148 mount)
149 # Mount all ext3 partitions found (opt: mount).
150 # Get the list of partitions.
151 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
152 # Mount filesystems rw.
153 for device in $DEVICES_LIST
154 do
155 name=${device#/dev/}
156 # Device can be already used by home=usb.
157 if ! mount | grep ^$device >/dev/null; then
158 echo "Mounting partition: $name on /mnt/$name"
159 mkdir /mnt/$name
160 mount $device /mnt/$name
161 fi
162 done ;;
163 mount-packages)
164 # Mount and install packages-XXX.iso (useful without Internet
165 # connection).
166 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
167 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
168 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
169 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
170 if [ -n "$PKGDEV" ]; then
171 echo -n "Mounting packages archive from $PKGDEV..."
172 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
173 status
174 /packages/install.sh
175 fi ;;
176 wm=*)
177 # Check for a Window Manager (for a flavor, default WM can be changed
178 # with boot options or with an addfile in /etc/X11/wm.default.
179 WM=${opt#wm=}
180 mkdir -p /etc/X11
181 case $WM in
182 jwm)
183 echo "jwm" > /etc/X11/wm.default ;;
184 ob|openbox|openbox-session)
185 echo "openbox" > /etc/X11/wm.default ;;
186 e17|enlightenment|enlightenment_start)
187 echo "enlightenment" > /etc/X11/wm.default ;;
188 esac ;;
189 *)
190 continue ;;
191 esac
192 done
194 # If no default WM fallback to Openbox (we never know).
195 if [ ! -f /etc/X11/wm.default ]; then
196 echo "openbox" > /etc/X11/wm.default
197 fi
199 # Activate an eventual swap file or partition.
200 if [ "`fdisk -l | grep swap`" ]; then
201 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
202 echo "Swap memory detected on: $SWAP_DEV"
203 add_swap_in_fstab $SWAP_DEV
204 done
205 fi
206 if grep -q swap /etc/fstab; then
207 echo "Activating swap memory..."
208 swapon -a
209 fi