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

bootopts.sh: fix uid/gid for vfat/ntfs case
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 30 18:24:28 2013 +0100 (2013-10-30)
parents 514c674eb843
children 86ae53480b99
rev   line source
pankso@6 1 #!/bin/sh
pankso@302 2 #
pankso@302 3 # /etc/init.d/bootopts.sh : SliTaz boot options from the cmdline
pankso@6 4 #
pankso@160 5 # Earlier boot options are in rcS, ex: config= and modprobe=
pankso@153 6 #
pankso@6 7 . /etc/init.d/rc.functions
pankso@6 8
pascal@290 9 # Get first usb disk
pankso@302 10 usb_device() {
pascal@290 11 cd /sys/block
pascal@290 12 for i in sd* sda ; do
pascal@291 13 grep -qs 1 $i/removable && break
pascal@290 14 done
pascal@290 15 echo $i
pascal@290 16 }
pascal@290 17
pankso@160 18 # Parse /proc/cmdline for boot options.
pankso@302 19 echo "Checking for SliTaz cmdline options..."
pankso@162 20
pankso@302 21 for opt in $(cat /proc/cmdline)
pankso@160 22 do
pankso@160 23 case $opt in
pankso@160 24 eject)
pankso@160 25 # Eject cdrom.
pankso@160 26 eject /dev/cdrom ;;
pankso@262 27 autologin)
pankso@262 28 # Autologin option to skip first graphic login prompt.
pankso@262 29 echo "auto_login yes" >> /etc/slim.conf ;;
pankso@262 30 lang=*)
pankso@262 31 # Check for a specified locale (lang=*).
pankso@262 32 LANG=${opt#lang=}
pankso@300 33 /sbin/tazlocale $LANG ;;
pankso@262 34 kmap=*)
pankso@262 35 # Check for a specified keymap (kmap=*).
pankso@262 36 KEYMAP=${opt#kmap=}
pankso@262 37 echo -n "Setting system keymap to: $KEYMAP..."
pankso@262 38 echo "$KEYMAP" > /etc/keymap.conf
pankso@262 39 status ;;
pankso@262 40 home=*)
pankso@262 41 # Check for a specified home partition (home=*) and check for
pankso@262 42 # user home dir. Note: home=usb is a shorter and easier way to
pankso@262 43 # have home=/dev/sda1.
pankso@262 44 DEVICE=${opt#home=}
pascal@290 45 [ "$DEVICE" = "usb" ] && DEVICE="$(usb_device)1"
pankso@262 46 echo "Home has been specified to $DEVICE..."
pankso@283 47 DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'`
pankso@262 48 if [ -z "$DEVID" ]; then
pankso@262 49 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
pankso@262 50 USBDELAY=$((2+$USBDELAY))
pankso@262 51 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
pankso@262 52 sleep $USBDELAY
pankso@262 53 fi
pankso@262 54 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
pankso@262 55 DEVID=$DEVICE
pankso@262 56 if [ -x /sbin/blkid ]; then
pankso@262 57 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
pankso@283 58 DEVID=`/sbin/blkid | sed 'p;s/"//g' | fgrep "$DEVICE" | sed 's/:.*//;q'`
pankso@262 59 fi
pankso@262 60 DEVID=${DEVID##*/}
pankso@283 61 if [ -n "$DEVID" ] && fgrep -q "$DEVID" /proc/partitions ; then
pankso@262 62 echo "Mounting /home on /dev/$DEVID... "
pankso@262 63 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
pascal@334 64 mount /dev/$DEVID /home &&
pascal@289 65 case "$(/sbin/blkid | grep /dev/$DEVID:)" in
pascal@332 66 *\"ntfs\"*|*\"vfat\"*) mount.posixovl -F /home ;;
pankso@300 67 esac
pascal@334 68 mount /home -o remount,uid=1000,gid=100 2>/dev/null
pankso@262 69 # Check if swap file must be generated in /home: swap=size (Mb).
pankso@262 70 # This option is only used within home=device.
pankso@262 71 if grep -q "swap=[1-9]*" /proc/cmdline; then
pankso@262 72 SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
pankso@262 73 # DD to gen a virtual disk.
pankso@262 74 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
pankso@262 75 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
pankso@262 76 # Make the Linux swap filesystem.
pankso@262 77 mkswap /home/swap
pankso@262 78 add_swap_in_fstab /home/swap
pankso@262 79 fi
pankso@262 80 else
pankso@262 81 echo "Unable to find $DEVICE... "
pankso@262 82 fi
pankso@262 83 # Move all user dir if needed.
pankso@262 84 if [ ! -d "/home/$USER" ] ; then
pankso@262 85 mv /tmp/$USER-files /home/$USER
pankso@262 86 chown -R $USER.users /home/$USER
pankso@262 87 else
pankso@262 88 rm -rf /tmp/$USER-files
pankso@262 89 fi
pankso@262 90 # Install all packages in /home/boot/packages. In live CD and
pankso@262 91 # USB mode the option home= mounts the device on /home, so we
pankso@262 92 # already have a boot directory with the Kernel and rootfs.
pankso@262 93 if [ -d "/home/boot/packages" ]; then
pankso@262 94 for pkg in /home/boot/packages/*.tazpkg
pankso@262 95 do
pankso@262 96 tazpkg install $pkg
pankso@262 97 done
pankso@262 98 fi
pankso@262 99 # We can have custom files in /home/boot/rootfs to overwrite
pankso@262 100 # the one packed into the Live system.
pankso@262 101 if [ -d "/home/boot/rootfs" ]; then
pankso@262 102 cp -a /home/boot/rootfs/* /
pankso@262 103 fi ;;
pankso@160 104 laptop)
pankso@171 105 # Enable Kernel Laptop mode.
pankso@171 106 echo "5" > /proc/sys/vm/laptop_mode ;;
pankso@160 107 mount)
pankso@160 108 # Mount all ext3 partitions found (opt: mount).
pankso@160 109 # Get the list of partitions.
pascal@228 110 DEVICES_LIST=`fdisk -l | sed '/83 Linux/!d;s/ .*//'`
pankso@160 111 # Mount filesystems rw.
pankso@160 112 for device in $DEVICES_LIST
pankso@160 113 do
pankso@160 114 name=${device#/dev/}
pankso@160 115 # Device can be already used by home=usb.
pankso@160 116 if ! mount | grep ^$device >/dev/null; then
pankso@160 117 echo "Mounting partition: $name on /mnt/$name"
pankso@160 118 mkdir /mnt/$name
pankso@160 119 mount $device /mnt/$name
pankso@160 120 fi
pankso@160 121 done ;;
pankso@160 122 mount-packages)
gokhlayeh@241 123 # Mount and install packages-XXX.iso (useful without Internet
pankso@160 124 # connection).
pankso@160 125 PKGSIGN="LABEL=\"packages-$(cat /etc/slitaz-release)\" TYPE=\"iso9660\""
pankso@160 126 PKGDEV=$(blkid | grep "$PKGSIGN" | cut -d: -f1)
pankso@160 127 [ -z "$PKGDEV" -a -L /dev/cdrom ] && \
pankso@160 128 PKGDEV=$(blkid /dev/cdrom | grep "$PKGSIGN" | cut -d: -f1)
pankso@160 129 if [ -n "$PKGDEV" ]; then
pankso@160 130 echo -n "Mounting packages archive from $PKGDEV..."
pankso@160 131 mkdir /packages && mount -t iso9660 -o ro $PKGDEV /packages
pankso@160 132 status
pankso@160 133 /packages/install.sh
pankso@160 134 fi ;;
pankso@262 135 wm=*)
pankso@262 136 # Check for a Window Manager (for a flavor, default WM can be changed
pankso@299 137 # with boot options or via /etc/slitaz/applications.conf).
pankso@262 138 WM=${opt#wm=}
pankso@262 139 case $WM in
pankso@262 140 ob|openbox|openbox-session)
pankso@299 141 WM=openbox-session ;;
pankso@262 142 e17|enlightenment|enlightenment_start)
pankso@299 143 WM=enlightenment ;;
pankso@299 144 razorqt|razor-session)
pankso@299 145 WM=razor-session ;;
pankso@299 146 esac
pankso@299 147 sed -i s/"WINDOW_MANAGER=.*"/"WINDOW_MANAGER=\"$WM\""/ \
pankso@299 148 /etc/slitaz/applications.conf ;;
pankso@160 149 *)
pankso@160 150 continue ;;
pankso@160 151 esac
pankso@160 152 done
pankso@160 153
pascal@325 154 # Default user account without password (uid=1000). In live mode the option
pascal@325 155 # user=name can be used, but user must be added before home= to have home dir.
pascal@325 156 # This option is not handled by a loop and case like others and has no
pascal@325 157 # effect on an installed system.
pascal@333 158 if ! grep -q "100[0-9]:100" /etc/passwd; then
pascal@325 159 if fgrep -q "user=" /proc/cmdline; then
pascal@325 160 USER=$(cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/')
pascal@325 161 # Avoid usage of an existing system user or root.
pascal@325 162 if grep -q ^$USER /etc/passwd; then
pascal@325 163 USER=tux
pascal@325 164 fi
pascal@325 165 else
pascal@325 166 USER=tux
pascal@325 167 fi
pascal@325 168 echo -n "Configuring user and group: $USER..."
pascal@325 169 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER
pascal@325 170 passwd -d $USER >/dev/null
pascal@325 171 status
pascal@325 172 # Audio and cdrom group.
pascal@325 173 addgroup $USER audio
pascal@325 174 addgroup $USER cdrom
pascal@325 175 addgroup $USER video
pascal@325 176 addgroup $USER tty
pascal@325 177 # Slim default user.
pascal@325 178 if [ -f /etc/slim.conf ]; then
pascal@325 179 sed -i s/"default_user .*"/"default_user $USER"/\
pascal@325 180 /etc/slim.conf
pascal@325 181 fi
pascal@325 182 fi
pascal@325 183
pankso@262 184 # If no default WM fallback to Openbox (we never know).
pankso@262 185 if [ ! -f /etc/X11/wm.default ]; then
pankso@262 186 echo "openbox" > /etc/X11/wm.default
pankso@262 187 fi