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

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