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 | |
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')
-rw-r--r-- | eclass/ChangeLog | 5 | ||||
-rw-r--r-- | eclass/user.eclass | 64 |
2 files changed, 66 insertions, 3 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog index 530e35a7c6e3..365154902fb1 100644 --- a/eclass/ChangeLog +++ b/eclass/ChangeLog @@ -1,6 +1,9 @@ # ChangeLog for eclass directory # Copyright 1999-2012 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.316 2012/06/18 06:45:28 grobian Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.317 2012/06/18 16:51:34 axs Exp $ + + 18 Jun 2012; Ian Stakenvicius <axs@gentoo.org> user.eclass: + added 'esethome' to user.eclass 18 Jun 2012; Fabian Groffen <grobian@gentoo.org> flag-o-matic.eclass: Allow header and library paths flags in setup-allowed-flags(), bug #414641 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 |