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

Add option: user=name
author Christophe Lincoln <pankso@slitaz.org>
date Mon Jun 09 23:39:44 2008 +0200 (2008-06-09)
parents 4ac520b89d9b
children f54edda7c5fb
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 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 witout 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 else
81 USER=linux
82 fi
83 echo -n "Configuring user and group: $USER..."
84 echo "$USER:x:1000:1000:SliTaz User,,,:/home/$USER:/bin/sh" >> /etc/passwd
85 echo "$USER::14035:0:99999:7:::" >> /etc/shadow
86 echo "$USER:x:1000:" >> /etc/group
87 echo "$USER:!::" >> /etc/gshadow
88 status
89 # Audio group.
90 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
91 # /home/$USER files from /etc/skel.
92 if [ -d /etc/skel ]; then
93 cp -a /etc/skel /home/$USER
94 else
95 mkdir -p /home/$USER
96 fi
97 # set permissions.
98 chown -R $USER.$USER /home/$USER
99 # Slim default user.
100 if [ -f /etc/slim.conf ]; then
101 sed -i s/"default_user hacker"/"default_user $USER"/\
102 /etc/slim.conf
103 fi
104 fi
106 # Check for a specified home directory on cmdline (home=*).
107 #
108 if grep -q "home=usb" /proc/cmdline; then
109 DEVICE=sda1
110 mount_home
111 elif grep -q "home=" /proc/cmdline; then
112 DEVICE=`cat /proc/cmdline | sed 's/.*home=\([^ ]*\).*/\1/'`
113 mount_home
114 fi
116 # Active an eventual swap file in /home and on local hd.
117 #
118 if [ -f "/home/swap" ]; then
119 echo "Activing swap (/home/swap) memory..."
120 swapon /home/swap
121 fi
122 if [ "`fdisk -l | grep swap`" ]; then
123 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
124 echo "Swap memory detected on: $SWAP_DEV"
125 swapon $SWAP_DEV
126 done
127 fi
129 # Check for a specified locale (lang=*).
130 #
131 if grep -q "lang=*" /proc/cmdline; then
132 LANG=`cat /proc/cmdline | sed 's/.*lang=\([^ ]*\).*/\1/'`
133 echo -n "Setting system locale to: $LANG... "
134 echo "LANG=$LANG" > /etc/locale.conf
135 echo "LC_ALL=$LANG" >> /etc/locale.conf
136 status
137 fi
139 # Check for a specified keymap (kmap=*).
140 #
141 if grep -q "kmap=*" /proc/cmdline; then
142 KEYMAP=`cat /proc/cmdline | sed 's/.*kmap=\([^ ]*\).*/\1/'`
143 echo -n "Setting system keymap to: $KEYMAP..."
144 echo "$KEYMAP" > /etc/keymap.conf
145 status
146 fi
148 # Laptop option to load ac and battery Kernel modules.
149 if grep -q "laptop" /proc/cmdline; then
150 echo "Loading laptop modules: ac, battery, yenta_socket..."
151 modprobe ac
152 modprobe battery
153 modprobe yenta_socket
154 fi
156 # Check for a Window Manager (for a flavor, default WM can be changed
157 # with boot option or with an addfile in /etc/X11/wm.default.
158 if grep -q "wm=" /proc/cmdline; then
159 mkdir -p /etc/X11
160 WM=`cat /proc/cmdline | sed 's/.*wm=\([^ ]*\).*/\1/'`
161 case $WM in
162 jwm)
163 echo "jwm" > /etc/X11/wm.default ;;
164 ob|openbox|openbox-session)
165 echo "openbox" > /etc/X11/wm.default ;;
166 e17|enlightenment|enlightenment_start)
167 echo "enlightenment" > /etc/X11/wm.default ;;
168 esac
169 else
170 # If no default WM fallback to Openbox.
171 if [ ! -f /etc/X11/wm.default ]; then
172 echo "openbox" > /etc/X11/wm.default
173 fi
174 fi
176 # Check for option mount.
177 if grep -q "mount" /proc/cmdline; then
178 mount_partitions
179 fi