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