functions-users.sh revision 209513
1209513Simp#!/bin/sh 2209513Simp#- 3209513Simp# Copyright (c) 2010 iX Systems, 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 209513 2010-06-24 22:21:47Z imp $ 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 75209513Simp echo $line | grep "^userName=" >/dev/null 2>/dev/null 76209513Simp if [ "$?" = "0" ] 77209513Simp then 78209513Simp get_value_from_string "${line}" 79209513Simp USERNAME="$VAL" 80209513Simp fi 81209513Simp 82209513Simp echo $line | grep "^userComment=" >/dev/null 2>/dev/null 83209513Simp if [ "$?" = "0" ] 84209513Simp then 85209513Simp get_value_from_string "${line}" 86209513Simp USERCOMMENT="$VAL" 87209513Simp fi 88209513Simp 89209513Simp echo $line | grep "^userPass=" >/dev/null 2>/dev/null 90209513Simp if [ "$?" = "0" ] 91209513Simp then 92209513Simp get_value_from_string "${line}" 93209513Simp USERPASS="$VAL" 94209513Simp fi 95209513Simp 96209513Simp echo $line | grep "^userShell=" >/dev/null 2>/dev/null 97209513Simp if [ "$?" = "0" ] 98209513Simp then 99209513Simp get_value_from_string "${line}" 100209513Simp strip_white_space "$VAL" 101209513Simp USERSHELL="$VAL" 102209513Simp fi 103209513Simp 104209513Simp echo $line | grep "^userHome=" >/dev/null 2>/dev/null 105209513Simp if [ "$?" = "0" ] 106209513Simp then 107209513Simp get_value_from_string "${line}" 108209513Simp USERHOME="$VAL" 109209513Simp fi 110209513Simp 111209513Simp echo $line | grep "^userGroups=" >/dev/null 2>/dev/null 112209513Simp if [ "$?" = "0" ] 113209513Simp then 114209513Simp get_value_from_string "${line}" 115209513Simp USERGROUPS="$VAL" 116209513Simp fi 117209513Simp 118209513Simp 119209513Simp echo $line | grep "^commitUser" >/dev/null 2>/dev/null 120209513Simp if [ "$?" = "0" ] 121209513Simp then 122209513Simp # Found our flag to commit this user, lets check and do it 123209513Simp if [ ! -z "${USERNAME}" ] 124209513Simp then 125209513Simp 126209513Simp # Now add this user to the system, by building our args list 127209513Simp ARGS="-n ${USERNAME}" 128209513Simp 129209513Simp if [ ! -z "${USERCOMMENT}" ] 130209513Simp then 131209513Simp ARGS="${ARGS} -c \"${USERCOMMENT}\"" 132209513Simp fi 133209513Simp 134209513Simp if [ ! -z "${USERPASS}" ] 135209513Simp then 136209513Simp ARGS="${ARGS} -h 0" 137209513Simp echo "${USERPASS}" >${FSMNT}/.tmpPass 138209513Simp else 139209513Simp ARGS="${ARGS} -h -" 140209513Simp rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null 141209513Simp fi 142209513Simp 143209513Simp if [ ! -z "${USERSHELL}" ] 144209513Simp then 145209513Simp ARGS="${ARGS} -s \"${USERSHELL}\"" 146209513Simp else 147209513Simp ARGS="${ARGS} -s \"/nonexistant\"" 148209513Simp fi 149209513Simp 150209513Simp if [ ! -z "${USERHOME}" ] 151209513Simp then 152209513Simp ARGS="${ARGS} -m -d \"${USERHOME}\"" 153209513Simp fi 154209513Simp 155209513Simp if [ ! -z "${USERGROUPS}" ] 156209513Simp then 157209513Simp ARGS="${ARGS} -G \"${USERGROUPS}\"" 158209513Simp fi 159209513Simp 160209513Simp add_user "${ARGS}" 161209513Simp 162209513Simp # Unset our vars before looking for any more users 163209513Simp unset USERNAME USERCOMMENT USERPASS USERSHELL USERHOME USERGROUPS 164209513Simp else 165209513Simp exit_err "ERROR: commitUser was called without any userName= entry!!!" 166209513Simp fi 167209513Simp fi 168209513Simp 169209513Simp done <${CFGF} 170209513Simp 171209513Simp 172209513Simp # Check if we need to enable a user to auto-login to the desktop 173209513Simp check_autologin 174209513Simp 175209513Simp}; 176