2012-06-19 17:44:20 +04:00
|
|
|
# Copyright 1999-2012 Gentoo Foundation
|
2011-11-09 11:33:19 +04:00
|
|
|
# Distributed under the terms of the GNU General Public License v2
|
2012-06-23 22:14:17 +04:00
|
|
|
# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.22 2012/06/22 19:18:24 axs Exp $
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# @ECLASS: user.eclass
|
|
|
|
# @MAINTAINER:
|
|
|
|
# base-system@gentoo.org (Linux)
|
|
|
|
# Joe Jezak <josejx@gmail.com> (OS X)
|
|
|
|
# usata@gentoo.org (OS X)
|
|
|
|
# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD)
|
|
|
|
# @BLURB: user management in ebuilds
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# The user eclass contains a suite of functions that allow ebuilds
|
|
|
|
# to quickly make sure users in the installed system are sane.
|
|
|
|
|
2011-12-11 14:24:51 +04:00
|
|
|
if [[ ${___ECLASS_ONCE_USER} != "recur -_+^+_- spank" ]] ; then
|
|
|
|
___ECLASS_ONCE_USER="recur -_+^+_- spank"
|
|
|
|
|
2011-11-09 11:33:19 +04:00
|
|
|
# @FUNCTION: _assert_pkg_ebuild_phase
|
|
|
|
# @INTERNAL
|
|
|
|
# @USAGE: <calling func name>
|
|
|
|
_assert_pkg_ebuild_phase() {
|
|
|
|
case ${EBUILD_PHASE} in
|
2011-11-26 18:06:51 +04:00
|
|
|
setup|preinst|postinst) ;;
|
|
|
|
*)
|
2011-11-30 10:10:45 +04:00
|
|
|
eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:"
|
|
|
|
eerror "You may only call from pkg_{setup,preinst,postinst} functions."
|
2011-11-09 11:33:19 +04:00
|
|
|
eerror "Package fails at QA and at life. Please file a bug."
|
2011-11-30 10:10:45 +04:00
|
|
|
die "Bad package! $1 is only for use in some pkg_* functions!"
|
2011-11-09 11:33:19 +04:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# @FUNCTION: egetent
|
|
|
|
# @USAGE: <database> <key>
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5),
|
|
|
|
# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
|
|
|
|
#
|
|
|
|
# Supported databases: group passwd
|
|
|
|
egetent() {
|
|
|
|
local db=$1 key=$2
|
|
|
|
|
|
|
|
[[ $# -ge 3 ]] && die "usage: egetent <database> <key>"
|
|
|
|
|
|
|
|
case ${db} in
|
|
|
|
passwd|group) ;;
|
|
|
|
*) die "sorry, database '${db}' not yet supported; file a bug" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case ${CHOST} in
|
|
|
|
*-darwin[678])
|
|
|
|
case ${key} in
|
|
|
|
*[!0-9]*) # Non numeric
|
|
|
|
nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
|
|
|
|
;;
|
|
|
|
*) # Numeric
|
|
|
|
nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*-darwin*)
|
|
|
|
local mykey
|
|
|
|
case ${db} in
|
|
|
|
passwd) db="Users" mykey="UniqueID" ;;
|
|
|
|
group) db="Groups" mykey="PrimaryGroupID" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case ${key} in
|
|
|
|
*[!0-9]*) # Non numeric
|
|
|
|
dscl . -read /${db}/${key} 2>/dev/null |grep RecordName
|
|
|
|
;;
|
|
|
|
*) # Numeric
|
|
|
|
dscl . -search /${db} ${mykey} ${key} 2>/dev/null
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*-freebsd*|*-dragonfly*)
|
|
|
|
case ${db} in
|
|
|
|
passwd) db="user" ;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# lookup by uid/gid
|
|
|
|
local opts
|
|
|
|
if [[ ${key} == [[:digit:]]* ]] ; then
|
|
|
|
[[ ${db} == "user" ]] && opts="-u" || opts="-g"
|
|
|
|
fi
|
|
|
|
|
|
|
|
pw show ${db} ${opts} "${key}" -q
|
|
|
|
;;
|
|
|
|
*-netbsd*|*-openbsd*)
|
|
|
|
grep "${key}:\*:" /etc/${db}
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# ignore output if nscd doesn't exist, or we're not running as root
|
|
|
|
nscd -i "${db}" 2>/dev/null
|
|
|
|
getent "${db}" "${key}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# @FUNCTION: enewuser
|
|
|
|
# @USAGE: <user> [uid] [shell] [homedir] [groups]
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# Same as enewgroup, you are not required to understand how to properly add
|
|
|
|
# a user to the system. The only required parameter is the username.
|
|
|
|
# Default uid is (pass -1 for this) next available, default shell is
|
|
|
|
# /bin/false, default homedir is /dev/null, and there are no default groups.
|
|
|
|
enewuser() {
|
2011-11-30 10:10:45 +04:00
|
|
|
_assert_pkg_ebuild_phase ${FUNCNAME}
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# get the username
|
|
|
|
local euser=$1; shift
|
|
|
|
if [[ -z ${euser} ]] ; then
|
|
|
|
eerror "No username specified !"
|
|
|
|
die "Cannot call enewuser without a username"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# lets see if the username already exists
|
|
|
|
if [[ -n $(egetent passwd "${euser}") ]] ; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
einfo "Adding user '${euser}' to your system ..."
|
|
|
|
|
|
|
|
# options to pass to useradd
|
2011-11-26 18:06:51 +04:00
|
|
|
local opts=()
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# handle uid
|
|
|
|
local euid=$1; shift
|
|
|
|
if [[ -n ${euid} && ${euid} != -1 ]] ; then
|
|
|
|
if [[ ${euid} -gt 0 ]] ; then
|
|
|
|
if [[ -n $(egetent passwd ${euid}) ]] ; then
|
|
|
|
euid="next"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
eerror "Userid given but is not greater than 0 !"
|
|
|
|
die "${euid} is not a valid UID"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
euid="next"
|
|
|
|
fi
|
|
|
|
if [[ ${euid} == "next" ]] ; then
|
|
|
|
for ((euid = 101; euid <= 999; euid++)); do
|
|
|
|
[[ -z $(egetent passwd ${euid}) ]] && break
|
|
|
|
done
|
|
|
|
fi
|
2011-11-26 18:06:51 +04:00
|
|
|
opts+=( -u ${euid} )
|
2011-11-09 11:33:19 +04:00
|
|
|
einfo " - Userid: ${euid}"
|
|
|
|
|
|
|
|
# handle shell
|
|
|
|
local eshell=$1; shift
|
|
|
|
if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then
|
|
|
|
if [[ ! -e ${ROOT}${eshell} ]] ; then
|
|
|
|
eerror "A shell was specified but it does not exist !"
|
|
|
|
die "${eshell} does not exist in ${ROOT}"
|
|
|
|
fi
|
|
|
|
if [[ ${eshell} == */false || ${eshell} == */nologin ]] ; then
|
|
|
|
eerror "Do not specify ${eshell} yourself, use -1"
|
|
|
|
die "Pass '-1' as the shell parameter"
|
|
|
|
fi
|
|
|
|
else
|
2011-11-26 18:06:51 +04:00
|
|
|
for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do
|
|
|
|
[[ -x ${ROOT}${eshell} ]] && break
|
2011-11-09 11:33:19 +04:00
|
|
|
done
|
|
|
|
|
2011-11-26 18:06:51 +04:00
|
|
|
if [[ ${eshell} == "/dev/null" ]] ; then
|
2011-11-09 11:33:19 +04:00
|
|
|
eerror "Unable to identify the shell to use, proceeding with userland default."
|
|
|
|
case ${USERLAND} in
|
2011-11-26 18:06:51 +04:00
|
|
|
GNU) eshell="/bin/false" ;;
|
|
|
|
BSD) eshell="/sbin/nologin" ;;
|
|
|
|
Darwin) eshell="/usr/sbin/nologin" ;;
|
2011-11-09 11:33:19 +04:00
|
|
|
*) die "Unable to identify the default shell for userland ${USERLAND}"
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
einfo " - Shell: ${eshell}"
|
2011-11-26 18:06:51 +04:00
|
|
|
opts+=( -s "${eshell}" )
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# handle homedir
|
|
|
|
local ehome=$1; shift
|
|
|
|
if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
|
|
|
|
ehome="/dev/null"
|
|
|
|
fi
|
|
|
|
einfo " - Home: ${ehome}"
|
2011-11-26 18:06:51 +04:00
|
|
|
opts+=( -d "${ehome}" )
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# handle groups
|
|
|
|
local egroups=$1; shift
|
2011-11-30 10:10:45 +04:00
|
|
|
local g egroups_arr
|
|
|
|
IFS="," read -r -a egroups_arr <<<"${egroups}"
|
|
|
|
shift
|
|
|
|
if [[ ${#egroups_arr[@]} -gt 0 ]] ; then
|
|
|
|
local defgroup exgroups
|
|
|
|
for g in "${egroups_arr[@]}" ; do
|
2011-11-09 11:33:19 +04:00
|
|
|
if [[ -z $(egetent group "${g}") ]] ; then
|
|
|
|
eerror "You must add group ${g} to the system first"
|
|
|
|
die "${g} is not a valid GID"
|
|
|
|
fi
|
|
|
|
if [[ -z ${defgroup} ]] ; then
|
|
|
|
defgroup=${g}
|
|
|
|
else
|
2011-11-30 10:10:45 +04:00
|
|
|
exgroups+=",${g}"
|
2011-11-09 11:33:19 +04:00
|
|
|
fi
|
|
|
|
done
|
2011-11-26 18:06:51 +04:00
|
|
|
opts+=( -g "${defgroup}" )
|
2011-11-09 11:33:19 +04:00
|
|
|
if [[ ! -z ${exgroups} ]] ; then
|
2011-11-26 18:06:51 +04:00
|
|
|
opts+=( -G "${exgroups:1}" )
|
2011-11-09 11:33:19 +04:00
|
|
|
fi
|
|
|
|
fi
|
2011-11-30 10:10:45 +04:00
|
|
|
einfo " - Groups: ${egroups:-(none)}"
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# handle extra args
|
|
|
|
if [[ $# -gt 0 ]] ; then
|
|
|
|
die "extra arguments no longer supported; please file a bug"
|
|
|
|
else
|
2011-11-26 18:06:51 +04:00
|
|
|
local comment="added by portage for ${PN}"
|
|
|
|
opts+=( -c "${comment}" )
|
|
|
|
einfo " - GECOS: ${comment}"
|
2011-11-09 11:33:19 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# add the user
|
|
|
|
case ${CHOST} in
|
|
|
|
*-darwin*)
|
|
|
|
### Make the user
|
2011-11-26 18:06:51 +04:00
|
|
|
dscl . create "/users/${euser}" uid ${euid}
|
|
|
|
dscl . create "/users/${euser}" shell "${eshell}"
|
|
|
|
dscl . create "/users/${euser}" home "${ehome}"
|
|
|
|
dscl . create "/users/${euser}" realname "added by portage for ${PN}"
|
2011-11-09 11:33:19 +04:00
|
|
|
### Add the user to the groups specified
|
2011-11-30 10:10:45 +04:00
|
|
|
for g in "${egroups_arr[@]}" ; do
|
2011-11-26 18:06:51 +04:00
|
|
|
dscl . merge "/groups/${g}" users "${euser}"
|
2011-11-09 11:33:19 +04:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
|
|
|
|
*-freebsd*|*-dragonfly*)
|
2011-11-26 18:06:51 +04:00
|
|
|
pw useradd "${euser}" "${opts[@]}" || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*-netbsd*)
|
2011-11-26 18:06:51 +04:00
|
|
|
useradd "${opts[@]}" "${euser}" || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*-openbsd*)
|
|
|
|
# all ops the same, except the -g vs -g/-G ...
|
2011-11-26 18:06:51 +04:00
|
|
|
useradd -u ${euid} -s "${eshell}" \
|
|
|
|
-d "${ehome}" -g "${egroups}" "${euser}" || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2011-11-26 18:06:51 +04:00
|
|
|
useradd -r "${opts[@]}" "${euser}" || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ ! -e ${ROOT}/${ehome} ]] ; then
|
|
|
|
einfo " - Creating ${ehome} in ${ROOT}"
|
|
|
|
mkdir -p "${ROOT}/${ehome}"
|
2011-11-26 18:06:51 +04:00
|
|
|
chown "${euser}" "${ROOT}/${ehome}"
|
2011-11-09 11:33:19 +04:00
|
|
|
chmod 755 "${ROOT}/${ehome}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# @FUNCTION: enewgroup
|
|
|
|
# @USAGE: <group> [gid]
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# This function does not require you to understand how to properly add a
|
|
|
|
# group to the system. Just give it a group name to add and enewgroup will
|
|
|
|
# do the rest. You may specify the gid for the group or allow the group to
|
|
|
|
# allocate the next available one.
|
|
|
|
enewgroup() {
|
2011-11-30 10:10:45 +04:00
|
|
|
_assert_pkg_ebuild_phase ${FUNCNAME}
|
2011-11-09 11:33:19 +04:00
|
|
|
|
|
|
|
# get the group
|
2011-11-26 18:06:51 +04:00
|
|
|
local egroup=$1; shift
|
|
|
|
if [[ -z ${egroup} ]] ; then
|
2011-11-09 11:33:19 +04:00
|
|
|
eerror "No group specified !"
|
|
|
|
die "Cannot call enewgroup without a group"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# see if group already exists
|
2011-11-26 18:06:51 +04:00
|
|
|
if [[ -n $(egetent group "${egroup}") ]] ; then
|
2011-11-09 11:33:19 +04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
einfo "Adding group '${egroup}' to your system ..."
|
|
|
|
|
|
|
|
# handle gid
|
2011-11-26 18:06:51 +04:00
|
|
|
local egid=$1; shift
|
|
|
|
if [[ ! -z ${egid} ]] ; then
|
|
|
|
if [[ ${egid} -gt 0 ]] ; then
|
|
|
|
if [[ -n $(egetent group ${egid}) ]] ; then
|
2011-11-09 11:33:19 +04:00
|
|
|
egid="next available; requested gid taken"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
eerror "Groupid given but is not greater than 0 !"
|
|
|
|
die "${egid} is not a valid GID"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
egid="next available"
|
|
|
|
fi
|
|
|
|
einfo " - Groupid: ${egid}"
|
|
|
|
|
|
|
|
# handle extra
|
2011-11-26 18:06:51 +04:00
|
|
|
if [[ $# -gt 0 ]] ; then
|
2011-11-09 11:33:19 +04:00
|
|
|
die "extra arguments no longer supported; please file a bug"
|
|
|
|
fi
|
|
|
|
|
2011-11-26 18:06:51 +04:00
|
|
|
# Some targets need to find the next available GID manually
|
|
|
|
_enewgroup_next_gid() {
|
|
|
|
if [[ ${egid} == *[!0-9]* ]] ; then
|
2011-11-30 10:10:45 +04:00
|
|
|
# Non numeric
|
2011-11-26 18:06:51 +04:00
|
|
|
for ((egid = 101; egid <= 999; egid++)) ; do
|
|
|
|
[[ -z $(egetent group ${egid}) ]] && break
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-11-09 11:33:19 +04:00
|
|
|
# add the group
|
|
|
|
case ${CHOST} in
|
|
|
|
*-darwin*)
|
2011-11-26 18:06:51 +04:00
|
|
|
_enewgroup_next_gid
|
|
|
|
dscl . create "/groups/${egroup}" gid ${egid}
|
|
|
|
dscl . create "/groups/${egroup}" passwd '*'
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*-freebsd*|*-dragonfly*)
|
2011-11-26 18:06:51 +04:00
|
|
|
_enewgroup_next_gid
|
|
|
|
pw groupadd "${egroup}" -g ${egid} || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*-netbsd*)
|
2011-11-26 18:06:51 +04:00
|
|
|
_enewgroup_next_gid
|
|
|
|
groupadd -g ${egid} "${egroup}" || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2011-11-26 18:06:51 +04:00
|
|
|
local opts
|
|
|
|
if [[ ${egid} == *[!0-9]* ]] ; then
|
2011-11-30 10:10:45 +04:00
|
|
|
# Non numeric; let groupadd figure out a GID for us
|
2011-11-26 18:06:51 +04:00
|
|
|
opts=""
|
|
|
|
else
|
|
|
|
opts="-g ${egid}"
|
|
|
|
fi
|
2011-11-09 11:33:19 +04:00
|
|
|
# We specify -r so that we get a GID in the system range from login.defs
|
2011-11-26 18:06:51 +04:00
|
|
|
groupadd -r ${opts} "${egroup}" || die
|
2011-11-09 11:33:19 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# @FUNCTION: egethome
|
|
|
|
# @USAGE: <user>
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# Gets the home directory for the specified user.
|
|
|
|
egethome() {
|
|
|
|
local pos
|
|
|
|
|
|
|
|
[[ $# -eq 1 ]] || die "usage: egethome <user>"
|
|
|
|
|
|
|
|
case ${CHOST} in
|
|
|
|
*-darwin*|*-freebsd*|*-dragonfly*)
|
|
|
|
pos=9
|
|
|
|
;;
|
|
|
|
*) # Linux, NetBSD, OpenBSD, etc...
|
|
|
|
pos=6
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2011-11-26 18:06:51 +04:00
|
|
|
egetent passwd "$1" | cut -d: -f${pos}
|
2011-11-09 11:33:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# @FUNCTION: egetshell
|
|
|
|
# @USAGE: <user>
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# Gets the shell for the specified user.
|
|
|
|
egetshell() {
|
|
|
|
local pos
|
|
|
|
|
|
|
|
[[ $# -eq 1 ]] || die "usage: egetshell <user>"
|
|
|
|
|
|
|
|
case ${CHOST} in
|
|
|
|
*-darwin*|*-freebsd*|*-dragonfly*)
|
|
|
|
pos=10
|
|
|
|
;;
|
|
|
|
*) # Linux, NetBSD, OpenBSD, etc...
|
|
|
|
pos=7
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
egetent passwd "$1" | cut -d: -f${pos}
|
|
|
|
}
|
2011-12-11 14:24:51 +04:00
|
|
|
|
2012-06-19 17:44:20 +04:00
|
|
|
# @FUNCTION: esethome
|
|
|
|
# @USAGE: <user> <homedir>
|
|
|
|
# @DESCRIPTION:
|
|
|
|
# Update the home directory in a platform-agnostic way.
|
|
|
|
# Required parameters is the username and the new home directory.
|
|
|
|
# Specify -1 if you want to set home to the enewuser default
|
|
|
|
# of /dev/null.
|
|
|
|
# If the new home directory does not exist, it is created.
|
|
|
|
# Any previously existing home directory is NOT moved.
|
|
|
|
esethome() {
|
|
|
|
_assert_pkg_ebuild_phase ${FUNCNAME}
|
|
|
|
|
|
|
|
# get the username
|
|
|
|
local euser=$1; shift
|
|
|
|
if [[ -z ${euser} ]] ; then
|
|
|
|
eerror "No username specified !"
|
|
|
|
die "Cannot call esethome without a username"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# lets see if the username already exists
|
|
|
|
if [[ -z $(egetent passwd "${euser}") ]] ; then
|
|
|
|
ewarn "User does not exist, cannot set home dir -- skipping."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# handle homedir
|
|
|
|
local ehome=$1; shift
|
|
|
|
if [[ -z ${ehome} ]] ; then
|
|
|
|
eerror "No home directory specified !"
|
|
|
|
die "Cannot call esethome without a home directory or '-1'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${ehome} == "-1" ]] ; then
|
|
|
|
ehome="/dev/null"
|
|
|
|
fi
|
2012-06-23 22:14:17 +04:00
|
|
|
|
|
|
|
# exit with no message if home dir is up to date
|
|
|
|
if [[ $(egethome "${euser}") == ${ehome} ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
einfo "Updating home for user '${euser}' ..."
|
2012-06-19 17:44:20 +04:00
|
|
|
einfo " - Home: ${ehome}"
|
|
|
|
|
2012-06-23 22:14:17 +04:00
|
|
|
# ensure home directory exists, otherwise update will fail
|
|
|
|
if [[ ! -e ${ROOT}/${ehome} ]] ; then
|
|
|
|
einfo " - Creating ${ehome} in ${ROOT}"
|
|
|
|
mkdir -p "${ROOT}/${ehome}"
|
|
|
|
chown "${euser}" "${ROOT}/${ehome}"
|
|
|
|
chmod 755 "${ROOT}/${ehome}"
|
|
|
|
fi
|
|
|
|
|
2012-06-19 17:44:20 +04:00
|
|
|
# update the home directory
|
|
|
|
case ${CHOST} in
|
|
|
|
*-darwin*)
|
|
|
|
dscl . change "/users/${euser}" home "${ehome}"
|
|
|
|
;;
|
|
|
|
|
|
|
|
*-freebsd*|*-dragonfly*)
|
2012-06-23 22:14:17 +04:00
|
|
|
pw usermod "${euser}" -d "${ehome}" && return 0
|
|
|
|
[[ $? == 8 ]] && eerror "${euser} is in use, cannot update home"
|
|
|
|
eerror "There was an error when attempting to update the home directory for ${euser}"
|
|
|
|
eerror "Please update it manually on your system:"
|
|
|
|
eerror "\t pw usermod \"${euser}\" -d \"${ehome}\""
|
2012-06-19 17:44:20 +04:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2012-06-23 22:14:17 +04:00
|
|
|
usermod -d "${ehome}" "${euser}" && return 0
|
|
|
|
[[ $? == 8 ]] && eerror "${euser} is in use, cannot update home"
|
|
|
|
eerror "There was an error when attempting to update the home directory for ${euser}"
|
|
|
|
eerror "Please update it manually on your system (as root):"
|
|
|
|
eerror "\t usermod -d \"${ehome}\" \"${euser}\""
|
2012-06-19 17:44:20 +04:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2011-12-11 14:24:51 +04:00
|
|
|
fi
|