slitaz-boot-scripts diff etc/init.d/user-home.sh @ rev 254

Huge change in boot... we start X as soon as possible by default, for this we have to config keymap, locale, user and home before, let do that in rcS. Also some fixes such as TZ
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 29 16:06:08 2011 +0200 (2011-04-29)
parents
children c76406c5b7c5
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/etc/init.d/user-home.sh	Fri Apr 29 16:06:08 2011 +0200
     1.3 @@ -0,0 +1,105 @@
     1.4 +#!/bin/sh
     1.5 +# /etc/init.d/user.sh - SliTaz default user for live mode and /home.
     1.6 +#
     1.7 +# This script is called from the main boot script /etc/init/rcS
     1.8 +# to add a user for live mode and mount /home before we start Slim
     1.9 +# since we need a user to autologin and provide a desktop
    1.10 +#
    1.11 +# Default user account without password (uid=1000). In live mode the option
    1.12 +# user=name can be used, but user must be added before home= to have home dir.
    1.13 +# This option is not handled by a loop and case like others and has no
    1.14 +# effect on an installed system.
    1.15 +#
    1.16 +
    1.17 +if ! grep -q "100[0-9]:100[0-9]" /etc/passwd; then
    1.18 +	if grep -q "user=" /proc/cmdline; then
    1.19 +		USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
    1.20 +		# Avoid usage of an existing system user or root.
    1.21 +		if grep -q ^$USER /etc/passwd; then
    1.22 +			USER=tux
    1.23 +		fi
    1.24 +	else
    1.25 +		USER=tux
    1.26 +	fi
    1.27 +	echo -n "Configuring user and group: $USER..."
    1.28 +	adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER
    1.29 +	passwd -d $USER >/dev/null
    1.30 +	status
    1.31 +	# Audio and cdrom group.
    1.32 +	addgroup $USER audio
    1.33 +	addgroup $USER cdrom
    1.34 +	addgroup $USER video
    1.35 +	addgroup $USER tty
    1.36 +	# /home/$USER files from /etc/skel.
    1.37 +	# make user be only read/write by user
    1.38 +	chmod -R 700 /home/$USER
    1.39 +	# Slim default user.
    1.40 +	if [ -f /etc/slim.conf ]; then
    1.41 +		sed -i s/"default_user .*"/"default_user        $USER"/\
    1.42 +			/etc/slim.conf
    1.43 +	fi
    1.44 +fi
    1.45 +
    1.46 +# Check for a specified home partition (home=*) and check for
    1.47 +# user home dir. Note: home=usb is a shorter and easier way to
    1.48 +# have home=/dev/sda1.
    1.49 +#
    1.50 +if grep -q "home=" /proc/cmdline; then
    1.51 +	DEVICE=${opt#home=}
    1.52 +	[ "$DEVICE" = "usb" ] && DEVICE=sda1
    1.53 +	echo "Home has been specified to $DEVICE..."
    1.54 +	DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
    1.55 +	if [ -z "$DEVID" ]; then
    1.56 +		USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
    1.57 +		USBDELAY=$((2+$USBDELAY))
    1.58 +		echo "Sleeping $USBDELAY s to let the kernel detect the device... "
    1.59 +		sleep $USBDELAY
    1.60 +	fi
    1.61 +	USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
    1.62 +	DEVID=$DEVICE
    1.63 +	if [ -x /sbin/blkid ]; then
    1.64 +		# Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
    1.65 +		DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
    1.66 +	fi
    1.67 +	DEVID=${DEVID##*/}
    1.68 +	if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
    1.69 +		echo "Mounting /home on /dev/$DEVID... "
    1.70 +		[ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
    1.71 +		mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
    1.72 +			|| mount /dev/$DEVID /home
    1.73 +		# Check if swap file must be generated in /home: swap=size (Mb).
    1.74 +		# This option is only used within home=device.
    1.75 +		if grep -q "swap=[1-9]*" /proc/cmdline; then
    1.76 +			SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
    1.77 +			# DD to gen a virtual disk.
    1.78 +			echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
    1.79 +			dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
    1.80 +			# Make the Linux swap filesystem.
    1.81 +			mkswap /home/swap
    1.82 +			add_swap_in_fstab /home/swap
    1.83 +		fi
    1.84 +	else
    1.85 +		echo "Unable to find $DEVICE... "
    1.86 +	fi
    1.87 +	# Move all user dir if needed.
    1.88 +	if [ ! -d "/home/$USER" ] ; then
    1.89 +		mv /tmp/$USER-files /home/$USER
    1.90 +		chown -R $USER.users /home/$USER
    1.91 +	else
    1.92 +		rm -rf /tmp/$USER-files
    1.93 +	fi
    1.94 +	# Install all packages in /home/boot/packages. In live CD and
    1.95 +	# USB mode the option home= mounts the device on /home, so we
    1.96 +	# already have a boot directory with the Kernel and rootfs.
    1.97 +	if [ -d "/home/boot/packages" ]; then
    1.98 +		for pkg in /home/boot/packages/*.tazpkg
    1.99 +		do
   1.100 +			tazpkg install $pkg
   1.101 +		done
   1.102 +	fi
   1.103 +	# We can have custom files in /home/boot/rootfs to overwrite
   1.104 +	# the one packed into the Live system.
   1.105 +	if [ -d "/home/boot/rootfs" ]; then
   1.106 +		cp -a /home/boot/rootfs/* /
   1.107 +	fi
   1.108 +fi