Releasing debian version 4.0.1-1.
[live-config.git] / scripts / config / 0030-user-setup
1 #!/bin/sh
2
3 ## live-config(7) - System Configuration Scripts
4 ## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5 ##
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
9
10
11 User_setup ()
12 {
13         # Checking if package is installed or already configured
14         if [ ! -e /var/lib/dpkg/info/user-setup.list ] || \
15            [ -e /var/lib/live/config/user-setup ]
16         then
17                 return
18         fi
19
20         echo -n " user-setup"
21
22         # Reading kernel command line
23         for _PARAMETER in ${_CMDLINE}
24         do
25                 case "${_PARAMETER}" in
26                         live-config.user-default-groups=*|user-default-groups=*)
27                                 LIVE_USER_DEFAULT_GROUPS="${_PARAMETER#*user-default-groups=}"
28                                 ;;
29
30                         live-config.user-fullname=*|user-fullname=*)
31                                 LIVE_USER_FULLNAME="${_PARAMETER#*user-fullname=}"
32                                 ;;
33
34                         live-config.username=*|username=*)
35                                 LIVE_USERNAME="${_PARAMETER#*username=}"
36                                 ;;
37                 esac
38         done
39
40         Configure_user_setup
41 }
42
43 Configure_user_setup ()
44 {
45         # Checking if package is already configured differently
46         if grep -q "^${LIVE_USERNAME}:" /etc/passwd
47         then
48                 return
49         fi
50
51         # Adjust formating of groups
52         if [ -n "${LIVE_USER_DEFAULT_GROUPS}" ]
53         then
54                 LIVE_USER_DEFAULT_GROUPS="$(echo ${LIVE_USER_DEFAULT_GROUPS} | sed -e 's|,| |g')"
55         fi
56
57         # Make sure user is not in sudo group if sudo is disabled
58         if [ "${_NO_ROOT}" = "true" ]
59         then
60                 LIVE_USER_DEFAULT_GROUPS="$(echo ${LIVE_USER_DEFAULT_GROUPS} | sed -e 's|sudo||')"
61         fi
62
63         # Default password is: live
64         # passwords can be generated with 'echo "live" | mkpasswd -s',
65         # a blank password is 'U6aMy0wojraho'.
66         _PASSWORD="8Ab05sVQ4LLps"
67
68 cat > /debconf.live << EOF
69 user-setup passwd/make-user boolean true
70 user-setup passwd/root-password-crypted string *
71 user-setup passwd/user-password-crypted string ${_PASSWORD}
72 user-setup passwd/user-default-groups string ${LIVE_USER_DEFAULT_GROUPS}
73 user-setup passwd/user-fullname string ${LIVE_USER_FULLNAME}
74 user-setup passwd/username string ${LIVE_USERNAME}
75 user-setup passwd/user-uid string 1000
76 EOF
77
78         debconf-set-selections < /debconf.live
79         rm -f /debconf.live
80
81         # Workaround for bug in shadow
82         set +e
83         touch /etc/passwd-
84         chmod 0600 /etc/passwd-
85
86         /usr/lib/user-setup/user-setup-apply 2>&1 \
87         | grep -v "Shadow passwords are now on"
88         set -e
89
90         # Creating state file
91         touch /var/lib/live/config/user-setup
92 }
93
94 User_setup