diff options
author | Ian Stakenvicius <axs@gentoo.org> | 2012-06-18 16:51:34 +0000 |
---|---|---|
committer | Ian Stakenvicius <axs@gentoo.org> | 2012-06-18 16:51:34 +0000 |
commit | 37042d9aea6d4eb6f3215f9f684406e09d26fa51 (patch) | |
tree | fc0cc1406bb0358bf246363f858ff9d35654a6fb /eclass/user.eclass | |
parent | Add app-misc/empty, ebuild by James Le Cuirot <chewi@aura-online.co.uk>. Bug ... (diff) | |
download | gentoo-2-37042d9aea6d4eb6f3215f9f684406e09d26fa51.tar.gz gentoo-2-37042d9aea6d4eb6f3215f9f684406e09d26fa51.tar.bz2 gentoo-2-37042d9aea6d4eb6f3215f9f684406e09d26fa51.zip |
added 'esethome' to user.eclass
Diffstat (limited to 'eclass/user.eclass')
-rw-r--r-- | eclass/user.eclass | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/eclass/user.eclass b/eclass/user.eclass index 2b1fd0c3f5b4..d2b76c8e8221 100644 --- a/eclass/user.eclass +++ b/eclass/user.eclass @@ -1,6 +1,6 @@ -# Copyright 1999-2011 Gentoo Foundation +# Copyright 1999-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.18 2011/12/10 20:03:17 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.19 2012/06/18 16:51:34 axs Exp $ # @ECLASS: user.eclass # @MAINTAINER: @@ -387,4 +387,64 @@ egetshell() { egetent passwd "$1" | cut -d: -f${pos} } +# @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 + einfo " - Home: ${ehome}" + + # update the home directory + case ${CHOST} in + *-darwin*) + dscl . change "/users/${euser}" home "${ehome}" + ;; + + *-freebsd*|*-dragonfly*) + pw usermod "${euser}" -d "${ehome}" || die + ;; + + *) + usermod -d "${ehome}" "${euser}" || die + ;; + esac + + if [[ ! -e ${ROOT}/${ehome} ]] ; then + einfo " - Creating ${ehome} in ${ROOT}" + mkdir -p "${ROOT}/${ehome}" + chown "${euser}" "${ROOT}/${ehome}" + chmod 755 "${ROOT}/${ehome}" + fi +} + fi |