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