functions-users.sh revision 211730
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 211730 2010-08-24 06:11:46Z 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 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 96211730Simp echo $line | grep "^userShell=" >/dev/null 2>/dev/null 97211730Simp if [ "$?" = "0" ] 98211730Simp then 99211730Simp get_value_from_string "${line}" 100211730Simp strip_white_space "$VAL" 101211730Simp USERSHELL="$VAL" 102211730Simp fi 103209513Simp 104211730Simp echo $line | grep "^userHome=" >/dev/null 2>/dev/null 105211730Simp if [ "$?" = "0" ] 106211730Simp then 107211730Simp get_value_from_string "${line}" 108211730Simp USERHOME="$VAL" 109211730Simp fi 110209513Simp 111211730Simp echo $line | grep "^userGroups=" >/dev/null 2>/dev/null 112211730Simp if [ "$?" = "0" ] 113211730Simp then 114211730Simp get_value_from_string "${line}" 115211730Simp USERGROUPS="$VAL" 116211730Simp fi 117209513Simp 118209513Simp 119211730Simp echo $line | grep "^commitUser" >/dev/null 2>/dev/null 120211730Simp if [ "$?" = "0" ] 121211730Simp then 122211730Simp # Found our flag to commit this user, lets check and do it 123211730Simp if [ ! -z "${USERNAME}" ] 124211730Simp then 125209513Simp 126211730Simp # Now add this user to the system, by building our args list 127211730Simp ARGS="-n ${USERNAME}" 128209513Simp 129211730Simp if [ ! -z "${USERCOMMENT}" ] 130211730Simp then 131211730Simp ARGS="${ARGS} -c \"${USERCOMMENT}\"" 132211730Simp fi 133209513Simp 134211730Simp if [ ! -z "${USERPASS}" ] 135211730Simp then 136211730Simp ARGS="${ARGS} -h 0" 137211730Simp echo "${USERPASS}" >${FSMNT}/.tmpPass 138211730Simp else 139211730Simp ARGS="${ARGS} -h -" 140211730Simp rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null 141211730Simp fi 142209513Simp 143211730Simp if [ ! -z "${USERSHELL}" ] 144211730Simp then 145211730Simp ARGS="${ARGS} -s \"${USERSHELL}\"" 146211730Simp else 147211730Simp ARGS="${ARGS} -s \"/nonexistant\"" 148211730Simp fi 149209513Simp 150211730Simp if [ ! -z "${USERHOME}" ] 151211730Simp then 152211730Simp ARGS="${ARGS} -m -d \"${USERHOME}\"" 153211730Simp fi 154209513Simp 155211730Simp if [ ! -z "${USERGROUPS}" ] 156211730Simp then 157211730Simp ARGS="${ARGS} -G \"${USERGROUPS}\"" 158211730Simp fi 159209513Simp 160211730Simp add_user "${ARGS}" 161209513Simp 162211730Simp # Unset our vars before looking for any more users 163211730Simp unset USERNAME USERCOMMENT USERPASS USERSHELL USERHOME USERGROUPS 164211730Simp else 165211730Simp exit_err "ERROR: commitUser was called without any userName= entry!!!" 166211730Simp fi 167211730Simp 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