functions-users.sh revision 217234
1209513Simp#!/bin/sh 2209513Simp#- 3209552Simp# Copyright (c) 2010 iXsystems, Inc. All rights reserved. 4209513Simp# 5209513Simp# Redistribution and use in source and binary forms, with or without 6209513Simp# modification, are permitted provided that the following conditions 7209513Simp# are met: 8209513Simp# 1. Redistributions of source code must retain the above copyright 9209513Simp# notice, this list of conditions and the following disclaimer. 10209513Simp# 2. Redistributions in binary form must reproduce the above copyright 11209513Simp# notice, this list of conditions and the following disclaimer in the 12209513Simp# documentation and/or other materials provided with the distribution. 13209513Simp# 14209513Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15209513Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16209513Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17209513Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18209513Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19209513Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20209513Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21209513Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22209513Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23209513Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24209513Simp# SUCH DAMAGE. 25209513Simp# 26209513Simp# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-users.sh 217234 2011-01-10 19:57:18Z jpaetzel $ 27209513Simp 28209513Simp# Functions which runs commands on the system 29209513Simp 30209513Simp. ${BACKEND}/functions.sh 31209513Simp. ${BACKEND}/functions-parse.sh 32209513Simp 33209513Simp 34209513Simp# Function which checks and sets up auto-login for a user if specified 35209513Simpcheck_autologin() 36209513Simp{ 37209513Simp get_value_from_cfg autoLoginUser 38209513Simp if [ ! -z "${VAL}" -a "${INSTALLTYPE}" = "PCBSD" ] 39209513Simp then 40209513Simp AUTOU="${VAL}" 41209513Simp # Add the auto-login user line 42209513Simp sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc 43209513Simp 44209513Simp # Add the auto-login user line 45209513Simp sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc 46209513Simp 47209513Simp fi 48209513Simp}; 49209513Simp 50209513Simp# Function which actually runs the adduser command on the filesystem 51209513Simpadd_user() 52209513Simp{ 53209513Simp ARGS="${1}" 54209513Simp 55209513Simp if [ -e "${FSMNT}/.tmpPass" ] 56209513Simp then 57209513Simp # Add a user with a supplied password 58209513Simp run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}" 59209513Simp rc_halt "rm ${FSMNT}/.tmpPass" 60209513Simp else 61209513Simp # Add a user with no password 62209513Simp run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}" 63209513Simp fi 64209513Simp 65209513Simp}; 66209513Simp 67209513Simp# Function which reads in the config, and adds any users specified 68209513Simpsetup_users() 69209513Simp{ 70209513Simp 71209513Simp # We are ready to start setting up the users, lets read the config 72209513Simp while read line 73209513Simp do 74209513Simp 75211730Simp echo $line | grep "^userName=" >/dev/null 2>/dev/null 76211730Simp if [ "$?" = "0" ] 77211730Simp then 78211730Simp get_value_from_string "${line}" 79211730Simp USERNAME="$VAL" 80211730Simp fi 81209513Simp 82211730Simp echo $line | grep "^userComment=" >/dev/null 2>/dev/null 83211730Simp if [ "$?" = "0" ] 84211730Simp then 85211730Simp get_value_from_string "${line}" 86211730Simp USERCOMMENT="$VAL" 87211730Simp fi 88209513Simp 89211730Simp echo $line | grep "^userPass=" >/dev/null 2>/dev/null 90211730Simp if [ "$?" = "0" ] 91211730Simp then 92211730Simp get_value_from_string "${line}" 93211730Simp USERPASS="$VAL" 94211730Simp fi 95209513Simp 96217234Sjpaetzel echo $line | grep "^userEncPass=" >/dev/null 2>/dev/null 97217234Sjpaetzel if [ "$?" = "0" ] 98217234Sjpaetzel then 99217234Sjpaetzel get_value_from_string "${line}" 100217234Sjpaetzel USERENCPASS="$VAL" 101217234Sjpaetzel fi 102217234Sjpaetzel 103211730Simp echo $line | grep "^userShell=" >/dev/null 2>/dev/null 104211730Simp if [ "$?" = "0" ] 105211730Simp then 106211730Simp get_value_from_string "${line}" 107211730Simp strip_white_space "$VAL" 108211730Simp USERSHELL="$VAL" 109211730Simp fi 110209513Simp 111211730Simp echo $line | grep "^userHome=" >/dev/null 2>/dev/null 112211730Simp if [ "$?" = "0" ] 113211730Simp then 114211730Simp get_value_from_string "${line}" 115211730Simp USERHOME="$VAL" 116211730Simp fi 117209513Simp 118211730Simp echo $line | grep "^userGroups=" >/dev/null 2>/dev/null 119211730Simp if [ "$?" = "0" ] 120211730Simp then 121211730Simp get_value_from_string "${line}" 122211730Simp USERGROUPS="$VAL" 123211730Simp fi 124209513Simp 125209513Simp 126211730Simp echo $line | grep "^commitUser" >/dev/null 2>/dev/null 127211730Simp if [ "$?" = "0" ] 128211730Simp then 129211730Simp # Found our flag to commit this user, lets check and do it 130211730Simp if [ ! -z "${USERNAME}" ] 131211730Simp then 132209513Simp 133211730Simp # Now add this user to the system, by building our args list 134211730Simp ARGS="-n ${USERNAME}" 135209513Simp 136211730Simp if [ ! -z "${USERCOMMENT}" ] 137211730Simp then 138211730Simp ARGS="${ARGS} -c \"${USERCOMMENT}\"" 139211730Simp fi 140209513Simp 141211730Simp if [ ! -z "${USERPASS}" ] 142211730Simp then 143211730Simp ARGS="${ARGS} -h 0" 144211730Simp echo "${USERPASS}" >${FSMNT}/.tmpPass 145217234Sjpaetzel elif [ ! -z "${USERENCPASS}" ] 146217234Sjpaetzel then 147217234Sjpaetzel ARGS="${ARGS} -H 0" 148217234Sjpaetzel echo "${USERENCPASS}" >${FSMNT}/.tmpPass 149211730Simp else 150211730Simp ARGS="${ARGS} -h -" 151211730Simp rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null 152211730Simp fi 153209513Simp 154211730Simp if [ ! -z "${USERSHELL}" ] 155211730Simp then 156211730Simp ARGS="${ARGS} -s \"${USERSHELL}\"" 157211730Simp else 158211730Simp ARGS="${ARGS} -s \"/nonexistant\"" 159211730Simp fi 160209513Simp 161211730Simp if [ ! -z "${USERHOME}" ] 162211730Simp then 163211730Simp ARGS="${ARGS} -m -d \"${USERHOME}\"" 164211730Simp fi 165209513Simp 166211730Simp if [ ! -z "${USERGROUPS}" ] 167211730Simp then 168211730Simp ARGS="${ARGS} -G \"${USERGROUPS}\"" 169211730Simp fi 170209513Simp 171211730Simp add_user "${ARGS}" 172209513Simp 173211730Simp # Unset our vars before looking for any more users 174217234Sjpaetzel unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS 175211730Simp else 176211730Simp exit_err "ERROR: commitUser was called without any userName= entry!!!" 177211730Simp fi 178211730Simp fi 179209513Simp 180209513Simp done <${CFGF} 181209513Simp 182209513Simp 183209513Simp # Check if we need to enable a user to auto-login to the desktop 184209513Simp check_autologin 185209513Simp 186209513Simp}; 187