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

adding default user modify slitaz-base-files (can't repack)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Jun 26 22:08:18 2008 +0200 (2008-06-26)
parents f36e99a70d2a
children 2c6efe056bb8
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=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 # slitaz-base-files are now modified
94 echo "slitaz-boot-scripts" > \
95 /var/lib/tazpkg/installed/slitaz-base-files/modifiers
96 # Audio group.
97 sed -i s/"audio:x:20:"/"audio:x:20:$USER"/ /etc/group
98 # /home/$USER files from /etc/skel.
99 if [ -d /etc/skel ]; then
100 cp -a /etc/skel /home/$USER
101 # Path for user dektop files.
102 for i in /home/$USER/.local/share/applications/*.desktop
103 do
104 sed -i s/"user_name"/"$USER"/g $i
105 done
106 else
107 mkdir -p /home/$USER
108 fi
109 # set permissions.
110 chown -R $USER.$USER /home/$USER
111 # Slim default user.
112 if [ -f /etc/slim.conf ]; then
113 sed -i s/"default_user hacker"/"default_user $USER"/\
114 /etc/slim.conf
115 fi
116 fi
118 # Check for a specified home directory on cmdline (home=*).
119 #
120 if grep -q "home=usb" /proc/cmdline; then
121 DEVICE=sda1
122 mount_home
123 elif grep -q "home=" /proc/cmdline; then
124 DEVICE=`cat /proc/cmdline | sed 's/.*home=\([^ ]*\).*/\1/'`
125 mount_home
126 fi
128 # Active an eventual swap file in /home and on local hd.
129 #
130 if [ -f "/home/swap" ]; then
131 echo "Activing swap (/home/swap) memory..."
132 swapon /home/swap
133 fi
134 if [ "`fdisk -l | grep swap`" ]; then
135 for SWAP_DEV in `fdisk -l | grep swap | awk '{ print $1 }'`; do
136 echo "Swap memory detected on: $SWAP_DEV"
137 swapon $SWAP_DEV
138 done
139 fi
141 # Check for a specified locale (lang=*).
142 #
143 if grep -q "lang=*" /proc/cmdline; then
144 LANG=`cat /proc/cmdline | sed 's/.*lang=\([^ ]*\).*/\1/'`
145 echo -n "Setting system locale to: $LANG... "
146 echo "LANG=$LANG" > /etc/locale.conf
147 echo "LC_ALL=$LANG" >> /etc/locale.conf
148 status
149 fi
151 # Check for a specified keymap (kmap=*).
152 #
153 if grep -q "kmap=*" /proc/cmdline; then
154 KEYMAP=`cat /proc/cmdline | sed 's/.*kmap=\([^ ]*\).*/\1/'`
155 echo -n "Setting system keymap to: $KEYMAP..."
156 echo "$KEYMAP" > /etc/keymap.conf
157 status
158 fi
160 # Laptop option to load ac and battery Kernel modules.
161 if grep -q "laptop" /proc/cmdline; then
162 echo "Loading laptop modules: ac, battery, yenta_socket..."
163 modprobe ac
164 modprobe battery
165 modprobe yenta_socket
166 fi
168 # Check for a Window Manager (for a flavor, default WM can be changed
169 # with boot option or with an addfile in /etc/X11/wm.default.
170 if grep -q "wm=" /proc/cmdline; then
171 mkdir -p /etc/X11
172 WM=`cat /proc/cmdline | sed 's/.*wm=\([^ ]*\).*/\1/'`
173 case $WM in
174 jwm)
175 echo "jwm" > /etc/X11/wm.default ;;
176 ob|openbox|openbox-session)
177 echo "openbox" > /etc/X11/wm.default ;;
178 e17|enlightenment|enlightenment_start)
179 echo "enlightenment" > /etc/X11/wm.default ;;
180 esac
181 else
182 # If no default WM fallback to Openbox.
183 if [ ! -f /etc/X11/wm.default ]; then
184 echo "openbox" > /etc/X11/wm.default
185 fi
186 fi
188 # Check for option mount.
189 if grep -q "mount" /proc/cmdline; then
190 mount_partitions
191 fi