functions-users.sh revision 209552
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 209552 2010-06-27 16:46:11Z imp $ 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 [ ! -z "${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 # We are ready to start setting up the users, lets read the config 72 while read line 73 do 74 75 echo $line | grep "^userName=" >/dev/null 2>/dev/null 76 if [ "$?" = "0" ] 77 then 78 get_value_from_string "${line}" 79 USERNAME="$VAL" 80 fi 81 82 echo $line | grep "^userComment=" >/dev/null 2>/dev/null 83 if [ "$?" = "0" ] 84 then 85 get_value_from_string "${line}" 86 USERCOMMENT="$VAL" 87 fi 88 89 echo $line | grep "^userPass=" >/dev/null 2>/dev/null 90 if [ "$?" = "0" ] 91 then 92 get_value_from_string "${line}" 93 USERPASS="$VAL" 94 fi 95 96 echo $line | grep "^userShell=" >/dev/null 2>/dev/null 97 if [ "$?" = "0" ] 98 then 99 get_value_from_string "${line}" 100 strip_white_space "$VAL" 101 USERSHELL="$VAL" 102 fi 103 104 echo $line | grep "^userHome=" >/dev/null 2>/dev/null 105 if [ "$?" = "0" ] 106 then 107 get_value_from_string "${line}" 108 USERHOME="$VAL" 109 fi 110 111 echo $line | grep "^userGroups=" >/dev/null 2>/dev/null 112 if [ "$?" = "0" ] 113 then 114 get_value_from_string "${line}" 115 USERGROUPS="$VAL" 116 fi 117 118 119 echo $line | grep "^commitUser" >/dev/null 2>/dev/null 120 if [ "$?" = "0" ] 121 then 122 # Found our flag to commit this user, lets check and do it 123 if [ ! -z "${USERNAME}" ] 124 then 125 126 # Now add this user to the system, by building our args list 127 ARGS="-n ${USERNAME}" 128 129 if [ ! -z "${USERCOMMENT}" ] 130 then 131 ARGS="${ARGS} -c \"${USERCOMMENT}\"" 132 fi 133 134 if [ ! -z "${USERPASS}" ] 135 then 136 ARGS="${ARGS} -h 0" 137 echo "${USERPASS}" >${FSMNT}/.tmpPass 138 else 139 ARGS="${ARGS} -h -" 140 rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null 141 fi 142 143 if [ ! -z "${USERSHELL}" ] 144 then 145 ARGS="${ARGS} -s \"${USERSHELL}\"" 146 else 147 ARGS="${ARGS} -s \"/nonexistant\"" 148 fi 149 150 if [ ! -z "${USERHOME}" ] 151 then 152 ARGS="${ARGS} -m -d \"${USERHOME}\"" 153 fi 154 155 if [ ! -z "${USERGROUPS}" ] 156 then 157 ARGS="${ARGS} -G \"${USERGROUPS}\"" 158 fi 159 160 add_user "${ARGS}" 161 162 # Unset our vars before looking for any more users 163 unset USERNAME USERCOMMENT USERPASS USERSHELL USERHOME USERGROUPS 164 else 165 exit_err "ERROR: commitUser was called without any userName= entry!!!" 166 fi 167 fi 168 169 done <${CFGF} 170 171 172 # Check if we need to enable a user to auto-login to the desktop 173 check_autologin 174 175}; 176