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

Avoid usage of an existing system user or root
author Christophe Lincoln <pankso@slitaz.org>
date Tue Jun 10 16:26:13 2008 +0200 (2008-06-10)
parents d76432221c42
children 2bcec684c19c
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 # Avoid usage of an existing system user or root.
81 if grep -q ^$USER /etc/passwd; then
82 USER=linux
83 fi
84 else
85 USER=linux
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 else
99 mkdir -p /home/$USER
100 fi
101 # set permissions.
102 chown -R $USER.$USER /home/$USER
103 # Slim default user.
104 if [ -f /etc/slim.conf ]; then
105 sed -i s/"default_user hacker"/"default_user $USER"/\
106 /etc/slim.conf
107 fi
108 fi
110 # Check for a specified home directory on cmdline (home=*).
111 #
112 if grep -q "home=usb" /proc/cmdline; then
113 DEVICE=sda1
114 mount_home
115 elif grep -q "home=" /proc/cmdline; then
116 DEVICE=`cat /proc/cmdline | sed 's/.*home=\([^ ]*\).*/\1/'`
117 mount_home
118 fi
120 # Active an eventual swap file in /home and on local hd.
121 #
122 if [ -f "/home/swap" ]; then
123 echo "Activing swap (/home/swap) memory..."
124 swapon /home/swap
125 fi
126 if [ "`fdisk -l | grep swap`" ]; then
127 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
128 echo "Swap memory detected on: $SWAP_DEV"
129 swapon $SWAP_DEV
130 done
131 fi
133 # Check for a specified locale (lang=*).
134 #
135 if grep -q "lang=*" /proc/cmdline; then
136 LANG=`cat /proc/cmdline | sed 's/.*lang=\([^ ]*\).*/\1/'`
137 echo -n "Setting system locale to: $LANG... "
138 echo "LANG=$LANG" > /etc/locale.conf
139 echo "LC_ALL=$LANG" >> /etc/locale.conf
140 status
141 fi
143 # Check for a specified keymap (kmap=*).
144 #
145 if grep -q "kmap=*" /proc/cmdline; then
146 KEYMAP=`cat /proc/cmdline | sed 's/.*kmap=\([^ ]*\).*/\1/'`
147 echo -n "Setting system keymap to: $KEYMAP..."
148 echo "$KEYMAP" > /etc/keymap.conf
149 status
150 fi
152 # Laptop option to load ac and battery Kernel modules.
153 if grep -q "laptop" /proc/cmdline; then
154 echo "Loading laptop modules: ac, battery, yenta_socket..."
155 modprobe ac
156 modprobe battery
157 modprobe yenta_socket
158 fi
160 # Check for a Window Manager (for a flavor, default WM can be changed
161 # with boot option or with an addfile in /etc/X11/wm.default.
162 if grep -q "wm=" /proc/cmdline; then
163 mkdir -p /etc/X11
164 WM=`cat /proc/cmdline | sed 's/.*wm=\([^ ]*\).*/\1/'`
165 case $WM in
166 jwm)
167 echo "jwm" > /etc/X11/wm.default ;;
168 ob|openbox|openbox-session)
169 echo "openbox" > /etc/X11/wm.default ;;
170 e17|enlightenment|enlightenment_start)
171 echo "enlightenment" > /etc/X11/wm.default ;;
172 esac
173 else
174 # If no default WM fallback to Openbox.
175 if [ ! -f /etc/X11/wm.default ]; then
176 echo "openbox" > /etc/X11/wm.default
177 fi
178 fi
180 # Check for option mount.
181 if grep -q "mount" /proc/cmdline; then
182 mount_partitions
183 fi