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

rcS: export SCREEN and source functions in user-home.sh
author Christophe Lincoln <pankso@slitaz.org>
date Fri Apr 29 17:43:22 2011 +0200 (2011-04-29)
parents a14abff6be90
children da846b200fe8
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 # /home/$USER files from /etc/skel.
35 # make user be only read/write by user
36 chmod -R 700 /home/$USER
37 # Slim default user.
38 if [ -f /etc/slim.conf ]; then
39 sed -i s/"default_user .*"/"default_user $USER"/\
40 /etc/slim.conf
41 fi
42 fi
44 # Check for a specified home partition (home=*) and check for
45 # user home dir. Note: home=usb is a shorter and easier way to
46 # have home=/dev/sda1.
47 #
48 if grep -q "home=" /proc/cmdline; then
49 DEVICE=${opt#home=}
50 [ "$DEVICE" = "usb" ] && DEVICE=sda1
51 echo "Home has been specified to $DEVICE..."
52 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
53 if [ -z "$DEVID" ]; then
54 USBDELAY=`cat /sys/module/usb_storage/parameters/delay_use`
55 USBDELAY=$((2+$USBDELAY))
56 echo "Sleeping $USBDELAY s to let the kernel detect the device... "
57 sleep $USBDELAY
58 fi
59 USER=`cat /etc/passwd | sed '/:1000:/!d;s/:.*//;q'`
60 DEVID=$DEVICE
61 if [ -x /sbin/blkid ]; then
62 # Can be a label, uuid, type or devname. DEVID gives us first: /dev/name.
63 DEVID=`/sbin/blkid | sed 'p;s/"//g' | grep "$DEVICE" | sed 's/:.*//;q'`
64 fi
65 DEVID=${DEVID##*/}
66 if [ -n "$DEVID" ] && grep -q "$DEVID" /proc/partitions ; then
67 echo "Mounting /home on /dev/$DEVID... "
68 [ -d /home/$USER ] && mv /home/$USER /tmp/$USER-files
69 mount /dev/$DEVID /home -o uid=1000,gid=1000 2>/dev/null \
70 || mount /dev/$DEVID /home
71 # Check if swap file must be generated in /home: swap=size (Mb).
72 # This option is only used within home=device.
73 if grep -q "swap=[1-9]*" /proc/cmdline; then
74 SWAP_SIZE=`sed 's/.*swap=\([^ ]*\).*/\1/' < /proc/cmdline`
75 # DD to gen a virtual disk.
76 echo "Generating swap file: /home/swap ($SWAP_SIZE)..."
77 dd if=/dev/zero of=/home/swap bs=1M count=$SWAP_SIZE
78 # Make the Linux swap filesystem.
79 mkswap /home/swap
80 add_swap_in_fstab /home/swap
81 fi
82 else
83 echo "Unable to find $DEVICE... "
84 fi
85 # Move all user dir if needed.
86 if [ ! -d "/home/$USER" ] ; then
87 mv /tmp/$USER-files /home/$USER
88 chown -R $USER.users /home/$USER
89 else
90 rm -rf /tmp/$USER-files
91 fi
92 # Install all packages in /home/boot/packages. In live CD and
93 # USB mode the option home= mounts the device on /home, so we
94 # already have a boot directory with the Kernel and rootfs.
95 if [ -d "/home/boot/packages" ]; then
96 for pkg in /home/boot/packages/*.tazpkg
97 do
98 tazpkg install $pkg
99 done
100 fi
101 # We can have custom files in /home/boot/rootfs to overwrite
102 # the one packed into the Live system.
103 if [ -d "/home/boot/rootfs" ]; then
104 cp -a /home/boot/rootfs/* /
105 fi
106 fi