slitaz-boot-scripts annotate etc/init.d/bootopts.sh @ rev 162

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