source: src-sh/pc-sysinstall/backend/functions-users.sh @ 727410d

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 727410d was 727410d, checked in by Kris Moore <kris@…>, 17 months ago

Make sure /home && /usr/home are created when we install

  • Property mode set to 100755
File size: 5.3 KB
Line 
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: head/usr.sbin/pc-sysinstall/backend/functions-users.sh 220059 2011-03-27 16:57:54Z jpaetzel $
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
35check_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
51add_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
68setup_users()
69{
70
71  # First check integrity of /home && /usr/home
72  if [ ! -e "${FSMNT}/home" ] ; then
73        run_chroot_cmd "ln -s /usr/home /home"
74  fi
75  if [ ! -d "${FSMNT}/usr/home" ] ; then
76        run_chroot_cmd "mkdir /usr/home"
77  fi
78
79  # We are ready to start setting up the users, lets read the config
80  while read line
81  do
82
83    echo $line | grep -q "^userName=" 2>/dev/null
84    if [ $? -eq 0 ]
85    then
86      get_value_from_string "${line}"
87      USERNAME="$VAL"
88    fi
89
90    echo $line | grep -q "^userComment=" 2>/dev/null
91    if [ $? -eq 0 ]
92    then
93      get_value_from_string "${line}"
94      USERCOMMENT="$VAL"
95    fi
96
97    echo $line | grep -q "^userPass=" 2>/dev/null
98    if [ $? -eq 0 ]
99    then
100      get_value_from_string "${line}"
101      USERPASS="$VAL"
102    fi
103
104    echo $line | grep -q "^userEncPass=" 2>/dev/null
105    if [ $? -eq 0 ]
106    then
107      get_value_from_string "${line}"
108      USERENCPASS="$VAL"
109    fi
110
111    echo $line | grep -q "^userShell=" 2>/dev/null
112    if [ $? -eq 0 ]
113    then
114      get_value_from_string "${line}"
115      strip_white_space "$VAL"
116      USERSHELL="$VAL"
117    fi
118
119    echo $line | grep -q "^userHome=" 2>/dev/null
120    if [ $? -eq 0 ]
121    then
122      get_value_from_string "${line}"
123      USERHOME="$VAL"
124    fi
125
126    echo $line | grep -q "^userGroups=" 2>/dev/null
127    if [ $? -eq 0 ]
128    then
129      get_value_from_string "${line}"
130      USERGROUPS="$VAL"
131    fi
132
133
134    echo $line | grep -q "^commitUser" 2>/dev/null
135    if [ $? -eq 0 ]
136    then
137      # Found our flag to commit this user, lets check and do it
138      if [ -n "${USERNAME}" ]
139      then
140
141        # Now add this user to the system, by building our args list
142        ARGS="-n ${USERNAME}"
143
144        if [ -n "${USERCOMMENT}" ]
145        then
146          ARGS="${ARGS} -c \"${USERCOMMENT}\""
147        fi
148         
149        if [ -n "${USERPASS}" ]
150        then
151          ARGS="${ARGS} -h 0"
152          echo "${USERPASS}" >${FSMNT}/.tmpPass
153        elif [ -n "${USERENCPASS}" ] 
154        then
155          ARGS="${ARGS} -H 0"
156          echo "${USERENCPASS}" >${FSMNT}/.tmpPass
157        else
158          ARGS="${ARGS} -h -"
159          rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null
160        fi
161
162        if [ -n "${USERSHELL}" ]
163        then
164          ARGS="${ARGS} -s \"${USERSHELL}\""
165        else
166          ARGS="${ARGS} -s \"/nonexistant\""
167        fi
168         
169        if [ -n "${USERHOME}" ]
170        then
171          ARGS="${ARGS} -m -d \"${USERHOME}\""
172        fi
173
174        if [ -n "${USERGROUPS}" ]
175        then
176          ARGS="${ARGS} -G \"${USERGROUPS}\""
177        fi
178
179        add_user "${ARGS}"
180
181        # Unset our vars before looking for any more users
182        unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS
183      else
184        exit_err "ERROR: commitUser was called without any userName= entry!!!" 
185      fi
186    fi
187
188  done <${CFGF}
189
190
191  # Check if we need to enable a user to auto-login to the desktop
192  check_autologin
193
194};
Note: See TracBrowser for help on using the repository browser.