]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - usr.sbin/pc-sysinstall/backend/functions-users.sh
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / usr.sbin / pc-sysinstall / backend / functions-users.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
8 # 1. Redistributions of source code must retain the above copyright
9 #    notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 #    notice, this list of conditions and the following disclaimer in the
12 #    documentation and/or other materials provided with the distribution.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 # SUCH DAMAGE.
25 #
26 # $FreeBSD$
27
28 # Functions which runs commands on the system
29
30 . ${BACKEND}/functions.sh
31 . ${BACKEND}/functions-parse.sh
32
33
34 # Function which checks and sets up auto-login for a user if specified
35 check_autologin()
36 {
37   get_value_from_cfg autoLoginUser
38   if [ -n "${VAL}"  -a "${INSTALLTYPE}" = "PCBSD" ]
39   then
40     AUTOU="${VAL}"
41     # Add the auto-login user line
42     sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
43
44     # Add the auto-login user line
45     sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc
46
47   fi
48 };
49
50 # Function which actually runs the adduser command on the filesystem
51 add_user()
52 {
53  ARGS="${1}"
54
55  if [ -e "${FSMNT}/.tmpPass" ]
56  then
57    # Add a user with a supplied password
58    run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
59    rc_halt "rm ${FSMNT}/.tmpPass"
60  else
61    # Add a user with no password
62    run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}"
63  fi
64
65 };
66
67 # Function which reads in the config, and adds any users specified
68 setup_users()
69 {
70
71   # We are ready to start setting up the users, lets read the config
72   while read line
73   do
74
75     echo $line | grep -q "^userName=" 2>/dev/null
76     if [ $? -eq 0 ]
77     then
78       get_value_from_string "${line}"
79       USERNAME="$VAL"
80     fi
81
82     echo $line | grep -q "^userComment=" 2>/dev/null
83     if [ $? -eq 0 ]
84     then
85       get_value_from_string "${line}"
86       USERCOMMENT="$VAL"
87     fi
88
89     echo $line | grep -q "^userPass=" 2>/dev/null
90     if [ $? -eq 0 ]
91     then
92       get_value_from_string "${line}"
93       USERPASS="$VAL"
94     fi
95
96     echo $line | grep -q "^userEncPass=" 2>/dev/null
97     if [ $? -eq 0 ]
98     then
99       get_value_from_string "${line}"
100       USERENCPASS="$VAL"
101     fi
102
103     echo $line | grep -q "^userShell=" 2>/dev/null
104     if [ $? -eq 0 ]
105     then
106       get_value_from_string "${line}"
107       strip_white_space "$VAL"
108       USERSHELL="$VAL"
109     fi
110
111     echo $line | grep -q "^userHome=" 2>/dev/null
112     if [ $? -eq 0 ]
113     then
114       get_value_from_string "${line}"
115       USERHOME="$VAL"
116     fi
117
118     echo $line | grep -q "^userGroups=" 2>/dev/null
119     if [ $? -eq 0 ]
120     then
121       get_value_from_string "${line}"
122       USERGROUPS="$VAL"
123     fi
124
125
126     echo $line | grep -q "^commitUser" 2>/dev/null
127     if [ $? -eq 0 ]
128     then
129       # Found our flag to commit this user, lets check and do it
130       if [ -n "${USERNAME}" ]
131       then
132
133         # Now add this user to the system, by building our args list
134         ARGS="-n ${USERNAME}"
135
136         if [ -n "${USERCOMMENT}" ]
137         then
138           ARGS="${ARGS} -c \"${USERCOMMENT}\""
139         fi
140          
141         if [ -n "${USERPASS}" ]
142         then
143           ARGS="${ARGS} -h 0"
144           echo "${USERPASS}" >${FSMNT}/.tmpPass
145         elif [ -n "${USERENCPASS}" ] 
146         then
147           ARGS="${ARGS} -H 0"
148           echo "${USERENCPASS}" >${FSMNT}/.tmpPass
149         else
150           ARGS="${ARGS} -h -"
151           rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null
152         fi
153
154         if [ -n "${USERSHELL}" ]
155         then
156           ARGS="${ARGS} -s \"${USERSHELL}\""
157         else
158           ARGS="${ARGS} -s \"/nonexistant\""
159         fi
160          
161         if [ -n "${USERHOME}" ]
162         then
163           ARGS="${ARGS} -m -d \"${USERHOME}\""
164         fi
165
166         if [ -n "${USERGROUPS}" ]
167         then
168           ARGS="${ARGS} -G \"${USERGROUPS}\""
169         fi
170
171         add_user "${ARGS}"
172
173         # Unset our vars before looking for any more users
174         unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS
175       else
176         exit_err "ERROR: commitUser was called without any userName= entry!!!" 
177       fi
178     fi
179
180   done <${CFGF}
181
182
183   # Check if we need to enable a user to auto-login to the desktop
184   check_autologin
185
186 };