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

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