Gentoo Archives: gentoo-dev

From: Ian Stakenvicius <axs@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] RFC: esethome
Date: Wed, 13 Jun 2012 19:36:25
Message-Id: 4FD8EB8C.90701@gentoo.org
In Reply to: Re: [gentoo-dev] RFC: enewuser should force updates to shell and home by Mike Frysinger
1 -----BEGIN PGP SIGNED MESSAGE-----
2 Hash: SHA256
3
4 On 13/06/12 03:14 PM, Mike Frysinger wrote:
5 >
6 > eset{home,shell} don't exist today, so you should implement them
7 > :) -mike
8
9 RFC - heavily based on enewuser.
10
11 - --- user.eclass [some timestamp]
12 +++ user.eclass.esethome [some other timestamp]
13 @@ -388,3 +388,63 @@
14 }
15
16 fi
17 +
18 +# @FUNCTION: esethome
19 +# @USAGE: <user> <homedir>
20 +# @DESCRIPTION:
21 +# Update the home directory in a platform-agnostic way.
22 +# Required parameters is the username and the new home directory.
23 +# Specify -1 if you want to set home to the enewuser default
24 +# of /dev/null.
25 +# If the new home directory does not exist, it is created.
26 +# Any previously existing home directory is NOT moved.
27 +esethome() {
28 + _assert_pkg_ebuild_phase ${FUNCNAME}
29 +
30 + # get the username
31 + local euser=$1; shift
32 + if [[ -z ${euser} ]] ; then
33 + eerror "No username specified !"
34 + die "Cannot call esethome without a username"
35 + fi
36 +
37 + # lets see if the username already exists
38 + if [[ ! -n $(egetent passwd "${euser}") ]] ; then
39 + ewarn "User does not exist, cannot set home. skipping."
40 + return 1
41 + fi
42 +
43 + # handle homedir
44 + local ehome=$1; shift
45 + if [[ -z ${ehome} ]] ; then
46 + eerror "No home directory specified !"
47 + die "Cannot call esethome without a home directory"
48 + fi
49 +
50 + if [[ ${ehome} == "-1" ]] ; then
51 + ehome="/dev/null"
52 + fi
53 + einfo " - Home: ${ehome}"
54 +
55 + # update the home directory
56 + case ${CHOST} in
57 + *-darwin*)
58 + dscl . change "/users/${euser}" home "${ehome}"
59 + ;;
60 +
61 + *-freebsd*|*-dragonfly*)
62 + pw usermod "${euser}" -d "${ehome}" || die
63 + ;;
64 +
65 + *)
66 + usermod -d "${ehome}" "${euser}" || die
67 + ;;
68 + esac
69 +
70 + if [[ ! -e ${ROOT}/${ehome} ]] ; then
71 + einfo " - Creating ${ehome} in ${ROOT}"
72 + mkdir -p "${ROOT}/${ehome}"
73 + chown "${euser}" "${ROOT}/${ehome}"
74 + chmod 755 "${ROOT}/${ehome}"
75 + fi
76 +}
77
78 -----BEGIN PGP SIGNATURE-----
79 Version: GnuPG v2.0.17 (GNU/Linux)
80
81 iF4EAREIAAYFAk/Y64wACgkQ2ugaI38ACPBZYQD9EzzmBDUon1YUNxaev5ONluAX
82 2GA32hOyvwGs2ylZPy8A/3RN8VNsa6XI++eHRdwjpsSZLw4sTVpa+fY2LZHSnWsh
83 =gLrd
84 -----END PGP SIGNATURE-----

Replies

Subject Author
Re: [gentoo-dev] RFC: esethome Mike Frysinger <vapier@g.o>