Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 688161 Details for
Bug 541406
user.eclass: does not respect ROOT
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
2021-02-23 up-to-date patchset
user.eclass.patch (text/plain), 6.30 KB, created by
dkjii
on 2021-02-24 01:01:26 UTC
(
hide
)
Description:
2021-02-23 up-to-date patchset
Filename:
MIME Type:
Creator:
dkjii
Created:
2021-02-24 01:01:26 UTC
Size:
6.30 KB
patch
obsolete
># Patch version 2 ># fixed egetent to handle uid/gid ># changed echown and efowners to use same syntax as chown/fowners ("user:group" instead of "user group") ># Note that if you want to usee other options (like "-R"), include them after "user:group" >diff --git a/eclass/user.eclass b/eclass/user.eclass >index 29910b5..1ae4034 100644 >--- a/eclass/user.eclass >+++ b/eclass/user.eclass >@@ -94,7 +94,19 @@ egetent() { > *) > # ignore output if nscd doesn't exist, or we're not running as root > nscd -i "${db}" 2>/dev/null >- getent "${db}" "${key}" >+ if [[ "${ROOT}" == "/" ]] ; then >+ getent "${db}" "${key}" >+ else >+ local euser >+ if [[ ${key} == [[:digit:]]* ]] ; then >+ euser=$(awk -F: '$3 == '${key}'{print $1}' ${ROOT}/etc/passwd) >+ else >+ euser=${key} >+ fi >+ if [[ "${euser}" != "" ]] ; then >+ grep --color=never "^${euser}" ${ROOT}/etc/${db} >+ fi >+ fi > ;; > esac > } >@@ -120,7 +132,11 @@ enewuser() { > if [[ -n $(egetent passwd "${euser}") ]] ; then > return 0 > fi >- einfo "Adding user '${euser}' to your system ..." >+ if [[ "${ROOT}" == "/" ]] ; then >+ einfo "Adding user '${euser}' to your system ..." >+ else >+ einfo "Adding user '${euser}' to ${ROOT} ..." >+ fi > > # options to pass to useradd > local opts=() >@@ -247,14 +263,18 @@ enewuser() { > ;; > > *) >- useradd -r "${opts[@]}" "${euser}" || die >+ if [[ "${ROOT}" != "/" ]] ; then >+ opts+=( --prefix "${ROOT}" ) >+ fi >+ einfo useradd -r "${opts[@]}" "${euser}" >+ useradd -r "${opts[@]}" "${euser}" || die > ;; > esac > > if [[ ! -e ${ROOT}/${ehome} ]] ; then > einfo " - Creating ${ehome} in ${ROOT}" > mkdir -p "${ROOT}/${ehome}" >- chown "${euser}" "${ROOT}/${ehome}" >+ chown "${euid}" "${ROOT}/${ehome}" > chmod 755 "${ROOT}/${ehome}" > fi > } >@@ -280,7 +300,11 @@ enewgroup() { > if [[ -n $(egetent group "${egroup}") ]] ; then > return 0 > fi >- einfo "Adding group '${egroup}' to your system ..." >+ if [[ "${ROOT}" == "/" ]] ; then >+ einfo "Adding group '${egroup}' to your system ..." >+ else >+ einfo "Adding group '${egroup}' to ${ROOT} ..." >+ fi > > # handle gid > local egid=$1; shift >@@ -339,8 +363,13 @@ enewgroup() { > else > opts="-g ${egid}" > fi >- # We specify -r so that we get a GID in the system range from login.defs >- groupadd -r ${opts} "${egroup}" || die >+ if [[ "${ROOT}" == "/" ]] ; then >+ # We specify -r so that we get a GID in the system range from login.defs >+ groupadd -r ${opts} "${egroup}" || die >+ else >+ einfo groupadd --prefix ${ROOT} -r ${opts} "${egroup}" >+ groupadd --prefix ${ROOT} -r ${opts} "${egroup}" || die >+ fi > ;; > esac > } >@@ -454,7 +483,11 @@ esethome() { > ;; > > *) >- usermod -d "${ehome}" "${euser}" && return 0 >+ if [[ "${ROOT}" == "/" ]] ; then >+ usermod -d "${ehome}" "${euser}" && return 0 >+ else >+ usermod --prefix ${ROOT} -d "${ehome}" "${euser}" && return 0 >+ fi > [[ $? == 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):" >@@ -463,4 +496,91 @@ esethome() { > esac > } > >+# @USAGE: <user> >+# @DESCRIPTION: >+# Gets the uid for the specified user. >+egetuid() { >+ [[ $# -eq 1 ]] || die "usage: egetuid <user>" >+ >+ egetent passwd "$1" | cut -d: -f3 || die >+} >+ >+# @USAGE: <group> >+# @DESCRIPTION: >+# Gets the gid for the specified group. >+egetgid() { >+ [[ $# -eq 1 ]] || die "usage: egetgid <group>" >+ >+ egetent group "$1" | cut -d: -f3 || die >+} >+ >+ >+# @USAGE: <user>:<group> <path> >+# @DESCRIPTION: >+# chown portage equivalent, honoring the ${ROOT} variable. >+echown() { >+ # get the user >+ local a=$1; shift >+ if [[ -z ${a} ]] ; then >+ eerror "No user specified !" >+ die "Cannot call echown without a user" >+ fi >+ >+ >+ local euid >+ local egid >+ >+ IFS=':' read -a fields <<< ${a} >+ >+ euser=${fields[0]} >+ egroup=${fields[1]} >+ if [[ "${euser}" != "" ]] ; then >+ euid=$(egetuid "${euser}") >+ fi >+ if [[ "${egroup}" != "" ]] ; then >+ egid=$(egetgid "${egroup}") >+ fi >+ if [[ "${egid}" == "" ]] ; then >+ einfo chown ${euid} $@ >+ chown ${euid} $@ || die >+ else >+ einfo chown ${euid}:${egid} $@ >+ chown ${euid}:${egid} $@ || die >+ fi >+ >+} >+ >+# @DESCRIPTION: >+# fowners honoring the ${ROOT} variable. >+efowners() { >+ # get the user:group >+ local a=$1; shift >+ if [[ -z ${a} ]] ; then >+ eerror "No user:group specified !" >+ die "Cannot call echown without a user" >+ fi >+ >+ >+ local euid >+ local egid >+ >+ IFS=':' read -a fields <<< ${a} >+ >+ euser=${fields[0]} >+ egroup=${fields[1]} >+ if [[ "${euser}" != "" ]] ; then >+ euid=$(egetuid "${euser}") >+ fi >+ if [[ "${egroup}" != "" ]] ; then >+ egid=$(egetgid "${egroup}") >+ fi >+ if [[ "${egid}" == "" ]] ; then >+ einfo fowners ${euid} $@ >+ fowners ${euid} $@ || die >+ else >+ einfo fowners ${euid}:${egid} $@ >+ fowners ${euid}:${egid} $@ || die >+ fi >+} >+ > fi
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 541406
:
434468
|
434472
|
434474
|
434740
|
688161
|
688164
|
688167
|
688170
|
688293