| 1 | # Copyright 1999-2011 Gentoo Foundation |
1 | # Copyright 1999-2012 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.18 2011/12/10 20:03:17 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/user.eclass,v 1.19 2012/06/18 16:51:34 axs Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: user.eclass |
5 | # @ECLASS: user.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org (Linux) |
7 | # base-system@gentoo.org (Linux) |
| 8 | # Joe Jezak <josejx@gmail.com> (OS X) |
8 | # Joe Jezak <josejx@gmail.com> (OS X) |
| … | |
… | |
| 385 | esac |
385 | esac |
| 386 | |
386 | |
| 387 | egetent passwd "$1" | cut -d: -f${pos} |
387 | egetent passwd "$1" | cut -d: -f${pos} |
| 388 | } |
388 | } |
| 389 | |
389 | |
|
|
390 | # @FUNCTION: esethome |
|
|
391 | # @USAGE: <user> <homedir> |
|
|
392 | # @DESCRIPTION: |
|
|
393 | # Update the home directory in a platform-agnostic way. |
|
|
394 | # Required parameters is the username and the new home directory. |
|
|
395 | # Specify -1 if you want to set home to the enewuser default |
|
|
396 | # of /dev/null. |
|
|
397 | # If the new home directory does not exist, it is created. |
|
|
398 | # Any previously existing home directory is NOT moved. |
|
|
399 | esethome() { |
|
|
400 | _assert_pkg_ebuild_phase ${FUNCNAME} |
|
|
401 | |
|
|
402 | # get the username |
|
|
403 | local euser=$1; shift |
|
|
404 | if [[ -z ${euser} ]] ; then |
|
|
405 | eerror "No username specified !" |
|
|
406 | die "Cannot call esethome without a username" |
|
|
407 | fi |
|
|
408 | |
|
|
409 | # lets see if the username already exists |
|
|
410 | if [[ -z $(egetent passwd "${euser}") ]] ; then |
|
|
411 | ewarn "User does not exist, cannot set home dir -- skipping." |
|
|
412 | return 1 |
|
|
413 | fi |
|
|
414 | |
|
|
415 | # handle homedir |
|
|
416 | local ehome=$1; shift |
|
|
417 | if [[ -z ${ehome} ]] ; then |
|
|
418 | eerror "No home directory specified !" |
|
|
419 | die "Cannot call esethome without a home directory or '-1'" |
|
|
420 | fi |
|
|
421 | |
|
|
422 | if [[ ${ehome} == "-1" ]] ; then |
|
|
423 | ehome="/dev/null" |
|
|
424 | fi |
|
|
425 | einfo " - Home: ${ehome}" |
|
|
426 | |
|
|
427 | # update the home directory |
|
|
428 | case ${CHOST} in |
|
|
429 | *-darwin*) |
|
|
430 | dscl . change "/users/${euser}" home "${ehome}" |
|
|
431 | ;; |
|
|
432 | |
|
|
433 | *-freebsd*|*-dragonfly*) |
|
|
434 | pw usermod "${euser}" -d "${ehome}" || die |
|
|
435 | ;; |
|
|
436 | |
|
|
437 | *) |
|
|
438 | usermod -d "${ehome}" "${euser}" || die |
|
|
439 | ;; |
|
|
440 | esac |
|
|
441 | |
|
|
442 | if [[ ! -e ${ROOT}/${ehome} ]] ; then |
|
|
443 | einfo " - Creating ${ehome} in ${ROOT}" |
|
|
444 | mkdir -p "${ROOT}/${ehome}" |
|
|
445 | chown "${euser}" "${ROOT}/${ehome}" |
|
|
446 | chmod 755 "${ROOT}/${ehome}" |
|
|
447 | fi |
|
|
448 | } |
|
|
449 | |
| 390 | fi |
450 | fi |