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