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

bootopts.sh: autologin support (need slim 1.3.1)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 28 23:09:36 2008 +0200 (2008-09-28)
parents 58cc6775e0f0
children 17a47d2b869e
line source
1 #!/bin/sh
2 # /etc/init.d/bootopts.sh - SliTaz boot options from the cmdline.
3 #
4 . /etc/init.d/rc.functions
6 # Check if swap file must be generated in /home: swap=size (Mb).
7 # This option is used with home=device.
8 gen_home_swap()
9 {
10 if grep -q "swap=[1-9]*" /proc/cmdline; then
11 SWAP_SIZE=`cat /proc/cmdline | sed 's/.*swap=\([^ ]*\).*/\1/'`
12 # DD to gen a virtual disk.
13 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
14 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
15 # Make the Linux swap filesystem.
16 mkswap /home/swap
17 fi
18 }
20 # Mount /home and check for user hacker home dir.
21 #
22 mount_home()
23 {
24 echo "Home has been specified to $DEVICE..."
25 echo "Sleeping 10 s to let the kernel detect the device... "
26 sleep 10
27 USER=`cat /etc/passwd | grep 1000 | cut -d ":" -f 1`
28 DEVID=$DEVICE
29 if [ -x /sbin/blkid ]; then
30 # Can be label, uuid or devname. DEVID give us first: /dev/name.
31 DEVID=`/sbin/blkid | grep $DEVICE | cut -d: -f1`
32 DEVID=${DEVID##*/}
33 fi
34 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
35 echo "Mounting /home on /dev/$DEVID... "
36 mv /home/$USER /tmp/$USER-files
37 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
38 || mount /dev/$DEVID /home
39 gen_home_swap
40 else
41 echo "Unable to find $DEVICE... "
42 fi
43 # Move all hacker dir if needed.
44 if [ ! -d "/home/$USER" ] ; then
45 mv /tmp/$USER-files /home/$USER
46 chown -R $USER.$USER /home/$USER
47 else
48 rm -rf /tmp/$USER-files
49 fi
50 }
52 # Mount all ext3 partitions found (opt: mount).
53 mount_partitions()
54 {
55 # Get the list of partitions.
56 DEVICES_LIST=`fdisk -l | grep 83 | cut -d " " -f 1`
57 # Mount filesystems rw.
58 for device in $DEVICES_LIST
59 do
60 name=${device#/dev/}
61 # Device can be already used by home=usb.
62 if ! mount | grep ^$device >/dev/null; then
63 echo "Mounting partition: $name on /mnt/$name"
64 mkdir /mnt/$name
65 mount $device /mnt/$name
66 fi
67 done
68 }
70 # Parse /proc/cmdline with grep.
71 #
73 echo "Parsing kernel cmdline for SliTaz live options... "
75 # user=name: Default user account without password (uid=1000).
76 #
77 if ! grep -q "1000:1000" /etc/passwd; then
78 if grep -q "user=" /proc/cmdline; then
79 USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
80 # Avoid usage of an existing system user or root.
81 if grep -q ^$USER /etc/passwd; then
82 USER=tux
83 fi
84 else
85 USER=tux
86 fi
87 echo -n "Configuring user and group: $USER..."
88 echo "$USER:x:1000:1000:SliTaz User,,,:/home/$USER:/bin/sh" >> /etc/passwd
89 echo "$USER::14035:0:99999:7:::" >> /etc/shadow
90 echo "$USER:x:1000:" >> /etc/group
91 echo "$USER:!::" >> /etc/gshadow
92 status
93 # Audio group.
94 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
95 # /home/$USER files from /etc/skel.
96 if [ -d /etc/skel ]; then
97 cp -a /etc/skel /home/$USER
98 # Path for user desktop files.
99 for i in /home/$USER/.local/share/applications/*.desktop
100 do
101 sed -i s/"user_name"/"$USER"/g $i
102 done
103 else
104 mkdir -p /home/$USER
105 fi
106 # set permissions.
107 chown -R $USER.$USER /home/$USER
108 # Slim default user.
109 if [ -f /etc/slim.conf ]; then
110 sed -i s/"default_user hacker"/"default_user $USER"/\
111 /etc/slim.conf
112 fi
113 fi
115 # Autologin option to skip first graphic login prompt.
116 if grep -q "autologin" /proc/cmdline; then
117 echo "auto_login yes" >> /etc/slim.conf
118 fi
120 # Check for a specified home directory on cmdline (home=*).
121 #
122 if grep -q "home=usb" /proc/cmdline; then
123 DEVICE=sda1
124 mount_home
125 elif grep -q "home=" /proc/cmdline; then
126 DEVICE=`cat /proc/cmdline | sed 's/.*home=\([^ ]*\).*/\1/'`
127 mount_home
128 fi
130 # Activate an eventual swap file in /home and on local HD.
131 #
132 if [ -f "/home/swap" ]; then
133 echo "Activating swap (/home/swap) memory..."
134 swapon /home/swap
135 fi
136 if [ "`fdisk -l | grep swap`" ]; then
137 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
138 echo "Swap memory detected on: $SWAP_DEV"
139 swapon $SWAP_DEV
140 done
141 fi
143 # Check for a specified locale (lang=*).
144 #
145 if grep -q "lang=*" /proc/cmdline; then
146 LANG=`cat /proc/cmdline | sed 's/.*lang=\([^ ]*\).*/\1/'`
147 echo -n "Setting system locale to: $LANG... "
148 echo "LANG=$LANG" > /etc/locale.conf
149 echo "LC_ALL=$LANG" >> /etc/locale.conf
150 status
151 fi
153 # Check for a specified keymap (kmap=*).
154 #
155 if grep -q "kmap=*" /proc/cmdline; then
156 KEYMAP=`cat /proc/cmdline | sed 's/.*kmap=\([^ ]*\).*/\1/'`
157 echo -n "Setting system keymap to: $KEYMAP..."
158 echo "$KEYMAP" > /etc/keymap.conf
159 status
160 fi
162 # Laptop option to load ac and battery Kernel modules.
163 if grep -q "laptop" /proc/cmdline; then
164 echo "Loading laptop modules: ac, battery, yenta_socket..."
165 modprobe ac
166 modprobe battery
167 modprobe yenta_socket
168 fi
170 # Check for a Window Manager (for a flavor, default WM can be changed
171 # with boot option or with an addfile in /etc/X11/wm.default.
172 if grep -q "wm=" /proc/cmdline; then
173 mkdir -p /etc/X11
174 WM=`cat /proc/cmdline | sed 's/.*wm=\([^ ]*\).*/\1/'`
175 case $WM in
176 jwm)
177 echo "jwm" > /etc/X11/wm.default ;;
178 ob|openbox|openbox-session)
179 echo "openbox" > /etc/X11/wm.default ;;
180 e17|enlightenment|enlightenment_start)
181 echo "enlightenment" > /etc/X11/wm.default ;;
182 esac
183 else
184 # If no default WM fallback to Openbox.
185 if [ ! -f /etc/X11/wm.default ]; then
186 echo "openbox" > /etc/X11/wm.default
187 fi
188 fi
190 # Check for option mount.
191 if grep -q "mount" /proc/cmdline; then
192 mount_partitions
193 fi