functions-users.sh revision 220059
140843Smsmith#!/bin/sh 240843Smsmith#- 340843Smsmith# Copyright (c) 2010 iXsystems, Inc. All rights reserved. 440843Smsmith# 540843Smsmith# Redistribution and use in source and binary forms, with or without 640843Smsmith# modification, are permitted provided that the following conditions 740843Smsmith# are met: 840843Smsmith# 1. Redistributions of source code must retain the above copyright 940843Smsmith# notice, this list of conditions and the following disclaimer. 1040843Smsmith# 2. Redistributions in binary form must reproduce the above copyright 1140843Smsmith# notice, this list of conditions and the following disclaimer in the 1240843Smsmith# documentation and/or other materials provided with the distribution. 1340843Smsmith# 1440843Smsmith# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1540843Smsmith# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1640843Smsmith# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1740843Smsmith# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1840843Smsmith# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1940843Smsmith# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2040843Smsmith# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2140843Smsmith# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2240843Smsmith# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2340843Smsmith# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2440843Smsmith# SUCH DAMAGE. 2540843Smsmith# 2640843Smsmith# $FreeBSD: head/usr.sbin/pc-sysinstall/backend/functions-users.sh 220059 2011-03-27 16:57:54Z jpaetzel $ 2740843Smsmith 2840843Smsmith# Functions which runs commands on the system 2940843Smsmith 3051786Sdcs. ${BACKEND}/functions.sh 3151786Sdcs. ${BACKEND}/functions-parse.sh 3240843Smsmith 3340843Smsmith 3440843Smsmith# Function which checks and sets up auto-login for a user if specified 3540843Smsmithcheck_autologin() 3640843Smsmith{ 3740843Smsmith get_value_from_cfg autoLoginUser 3840843Smsmith if [ -n "${VAL}" -a "${INSTALLTYPE}" = "PCBSD" ] 3940843Smsmith then 4040843Smsmith AUTOU="${VAL}" 4140843Smsmith # Add the auto-login user line 4240843Smsmith sed -i.bak "s/AutoLoginUser=/AutoLoginUser=${AUTOU}/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc 4340843Smsmith 4440843Smsmith # Add the auto-login user line 4540843Smsmith sed -i.bak "s/AutoLoginEnable=false/AutoLoginEnable=true/g" ${FSMNT}/usr/local/kde4/share/config/kdm/kdmrc 4640843Smsmith 4740843Smsmith fi 4840843Smsmith}; 4940843Smsmith 5040843Smsmith# Function which actually runs the adduser command on the filesystem 5140843Smsmithadd_user() 5240843Smsmith{ 5340843Smsmith ARGS="${1}" 5440843Smsmith 5540843Smsmith if [ -e "${FSMNT}/.tmpPass" ] 5640843Smsmith then 5740843Smsmith # Add a user with a supplied password 5840843Smsmith run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}" 5940843Smsmith rc_halt "rm ${FSMNT}/.tmpPass" 6040843Smsmith else 6140843Smsmith # Add a user with no password 6240843Smsmith run_chroot_cmd "cat /.tmpPass | pw useradd ${ARGS}" 6340843Smsmith fi 6440843Smsmith 6540843Smsmith}; 6640843Smsmith 6740843Smsmith# Function which reads in the config, and adds any users specified 6840843Smsmithsetup_users() 6940843Smsmith{ 7040843Smsmith 7140843Smsmith # We are ready to start setting up the users, lets read the config 7240843Smsmith while read line 7340843Smsmith do 7440843Smsmith 7540843Smsmith echo $line | grep -q "^userName=" 2>/dev/null 7640843Smsmith if [ $? -eq 0 ] 7740843Smsmith then 7840843Smsmith get_value_from_string "${line}" 7940843Smsmith USERNAME="$VAL" 8040843Smsmith fi 8140843Smsmith 8240843Smsmith echo $line | grep -q "^userComment=" 2>/dev/null 8340843Smsmith if [ $? -eq 0 ] 8440843Smsmith then 8540843Smsmith get_value_from_string "${line}" 8640843Smsmith USERCOMMENT="$VAL" 8740843Smsmith fi 8840843Smsmith 8940843Smsmith echo $line | grep -q "^userPass=" 2>/dev/null 9040843Smsmith if [ $? -eq 0 ] 9140843Smsmith then 9240843Smsmith get_value_from_string "${line}" 9340843Smsmith USERPASS="$VAL" 9440843Smsmith fi 9540843Smsmith 9640843Smsmith echo $line | grep -q "^userEncPass=" 2>/dev/null 9740843Smsmith if [ $? -eq 0 ] 9840843Smsmith then 9940843Smsmith get_value_from_string "${line}" 10040843Smsmith USERENCPASS="$VAL" 10140843Smsmith fi 10240843Smsmith 10340843Smsmith echo $line | grep -q "^userShell=" 2>/dev/null 10440843Smsmith if [ $? -eq 0 ] 10540843Smsmith then 10640843Smsmith get_value_from_string "${line}" 10740843Smsmith strip_white_space "$VAL" 10840843Smsmith USERSHELL="$VAL" 10940843Smsmith fi 11040843Smsmith 11140843Smsmith echo $line | grep -q "^userHome=" 2>/dev/null 11240843Smsmith if [ $? -eq 0 ] 11340843Smsmith then 11440843Smsmith get_value_from_string "${line}" 11540843Smsmith USERHOME="$VAL" 11640843Smsmith fi 11740843Smsmith 11840843Smsmith echo $line | grep -q "^userGroups=" 2>/dev/null 11940843Smsmith if [ $? -eq 0 ] 12040843Smsmith then 12140843Smsmith get_value_from_string "${line}" 12240843Smsmith USERGROUPS="$VAL" 12340843Smsmith fi 12440843Smsmith 12540843Smsmith 12640843Smsmith echo $line | grep -q "^commitUser" 2>/dev/null 12740843Smsmith if [ $? -eq 0 ] 12840843Smsmith then 12940843Smsmith # Found our flag to commit this user, lets check and do it 13040843Smsmith if [ -n "${USERNAME}" ] 13140843Smsmith then 13240843Smsmith 13340843Smsmith # Now add this user to the system, by building our args list 13440843Smsmith ARGS="-n ${USERNAME}" 13540843Smsmith 13640843Smsmith if [ -n "${USERCOMMENT}" ] 13740843Smsmith then 13840843Smsmith ARGS="${ARGS} -c \"${USERCOMMENT}\"" 13940843Smsmith fi 14040843Smsmith 14140843Smsmith if [ -n "${USERPASS}" ] 14240843Smsmith then 14340843Smsmith ARGS="${ARGS} -h 0" 14440843Smsmith echo "${USERPASS}" >${FSMNT}/.tmpPass 14540843Smsmith elif [ -n "${USERENCPASS}" ] 14640843Smsmith then 14740843Smsmith ARGS="${ARGS} -H 0" 14840843Smsmith echo "${USERENCPASS}" >${FSMNT}/.tmpPass 14940843Smsmith else 15040843Smsmith ARGS="${ARGS} -h -" 15140843Smsmith rm ${FSMNT}/.tmpPass 2>/dev/null 2>/dev/null 15240843Smsmith fi 15340843Smsmith 15440843Smsmith if [ -n "${USERSHELL}" ] 15540843Smsmith then 15640843Smsmith ARGS="${ARGS} -s \"${USERSHELL}\"" 15740843Smsmith else 15851786Sdcs ARGS="${ARGS} -s \"/nonexistant\"" 15951786Sdcs fi 16051786Sdcs 16143078Smsmith if [ -n "${USERHOME}" ] 16243078Smsmith then 16343078Smsmith ARGS="${ARGS} -m -d \"${USERHOME}\"" 16443078Smsmith fi 16543078Smsmith 16643078Smsmith if [ -n "${USERGROUPS}" ] 16743078Smsmith then 16843078Smsmith ARGS="${ARGS} -G \"${USERGROUPS}\"" 16940843Smsmith fi 17040843Smsmith 17140843Smsmith add_user "${ARGS}" 17240843Smsmith 17340843Smsmith # Unset our vars before looking for any more users 17440843Smsmith unset USERNAME USERCOMMENT USERPASS USERENCPASS USERSHELL USERHOME USERGROUPS 17540843Smsmith else 17640843Smsmith exit_err "ERROR: commitUser was called without any userName= entry!!!" 17740843Smsmith fi 17840843Smsmith fi 17940843Smsmith 18040843Smsmith done <${CFGF} 18140843Smsmith 18240843Smsmith 18340843Smsmith # Check if we need to enable a user to auto-login to the desktop 18440843Smsmith check_autologin 18540843Smsmith 18640843Smsmith}; 18740843Smsmith