slitaz-boot-scripts view etc/init.d/user-home.sh @ rev 259

Fix #36 - Sorry for that one
author Christophe Lincoln <pankso@slitaz.org>
date Sat Apr 30 01:58:14 2011 +0200 (2011-04-30)
parents c76406c5b7c5
children
line source
1 #!/bin/sh
2 # /etc/init.d/user.sh - SliTaz default user for live mode and /home.
3 #
4 # This script is called from the main boot script /etc/init/rcS
5 # to add a user for live mode and mount /home before we start Slim
6 # since we need a user to autologin and provide a desktop
7 #
8 # Default user account without password (uid=1000). In live mode the option
9 # user=name can be used, but user must be added before home= to have home dir.
10 # This option is not handled by a loop and case like others and has no
11 # effect on an installed system.
12 #
13 . /etc/init.d/rc.functions
15 if ! grep -q "100[0-9]:100[0-9]" /etc/passwd; then
16 if grep -q "user=" /proc/cmdline; then
17 USER=`cat /proc/cmdline | sed 's/.*user=\([^ ]*\).*/\1/'`
18 # Avoid usage of an existing system user or root.
19 if grep -q ^$USER /etc/passwd; then
20 USER=tux
21 fi
22 else
23 USER=tux
24 fi
25 echo -n "Configuring user and group: $USER..."
26 adduser -D -s /bin/sh -g "SliTaz User" -G users -h /home/$USER $USER
27 passwd -d $USER >/dev/null
28 status
29 # Audio and cdrom group.
30 addgroup $USER audio
31 addgroup $USER cdrom
32 addgroup $USER video
33 addgroup $USER tty
34 # Slim default user.
35 if [ -f /etc/slim.conf ]; then
36 sed -i s/"default_user .*"/"default_user $USER"/\
37 /etc/slim.conf
38 fi
39 fi
41 # Check for a specified home partition (home=*) and check for
42 # user home dir. Note: home=usb is a shorter and easier way to
43 # have home=/dev/sda1.
44 #
45 if grep -q "home=" /proc/cmdline; then
46 DEVICE=${opt#home=}
47 [ "$DEVICE" = "usb" ] && DEVICE=sda1
48 echo "Home has been specified to $DEVICE..."
49 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
50 if [ -z "$DEVID" ]; then
51 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
52 USBDELAY=$((2+$USBDELAY))
53 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
54 sleep $USBDELAY
55 fi
56 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
57 DEVID=$DEVICE
58 if [ -x /sbin/blkid ]; then
59 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
60 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
61 fi
62 DEVID=${DEVID##*/}
63 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
64 echo "Mounting /home on /dev/$DEVID... "
65 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
66 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
67 || mount /dev/$DEVID /home
68 # Check if swap file must be generated in /home: swap=size (Mb).
69 # This option is only used within home=device.
70 if grep -q "swap=[1-9]*" /proc/cmdline; then
71 SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
72 # DD to gen a virtual disk.
73 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
74 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
75 # Make the Linux swap filesystem.
76 mkswap /home/swap
77 add_swap_in_fstab /home/swap
78 fi
79 else
80 echo "Unable to find $DEVICE... "
81 fi
82 # Move all user dir if needed.
83 if [ ! -d "/home/$USER" ] ; then
84 mv /tmp/$USER-files /home/$USER
85 chown -R $USER.users /home/$USER
86 else
87 rm -rf /tmp/$USER-files
88 fi
89 # Install all packages in /home/boot/packages. In live CD and
90 # USB mode the option home= mounts the device on /home, so we
91 # already have a boot directory with the Kernel and rootfs.
92 if [ -d "/home/boot/packages" ]; then
93 for pkg in /home/boot/packages/*.tazpkg
94 do
95 tazpkg install $pkg
96 done
97 fi
98 # We can have custom files in /home/boot/rootfs to overwrite
99 # the one packed into the Live system.
100 if [ -d "/home/boot/rootfs" ]; then
101 cp -a /home/boot/rootfs/* /
102 fi
103 fi