From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/proj/prefix:master commit in: eclass/
Date: Mon, 17 Dec 2018 09:55:47 +0000 (UTC) [thread overview]
Message-ID: <1545040525.d6ffd48fbde60f371dd8b763b9ab9a4beecf282a.grobian@gentoo> (raw)
commit: d6ffd48fbde60f371dd8b763b9ab9a4beecf282a
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 17 09:55:25 2018 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon Dec 17 09:55:25 2018 +0000
URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=d6ffd48f
eclass: sync with gx86
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
eclass/autotools.eclass | 11 +-
eclass/flag-o-matic.eclass | 8 +-
eclass/gnuconfig.eclass | 99 ---------
eclass/java-utils-2.eclass | 23 +-
eclass/python-utils-r1.eclass | 1 +
eclass/toolchain-binutils.eclass | 19 +-
eclass/toolchain-funcs.eclass | 145 ++++++++----
eclass/user.eclass | 469 ---------------------------------------
8 files changed, 127 insertions(+), 648 deletions(-)
diff --git a/eclass/autotools.eclass b/eclass/autotools.eclass
index f30ac7414f..5a59c8d2d5 100644
--- a/eclass/autotools.eclass
+++ b/eclass/autotools.eclass
@@ -4,6 +4,7 @@
# @ECLASS: autotools.eclass
# @MAINTAINER:
# base-system@gentoo.org
+# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
# @BLURB: Regenerates auto* build scripts
# @DESCRIPTION:
# This eclass is for safely handling autotooled software packages that need to
@@ -25,6 +26,11 @@ fi
if [[ -z ${_AUTOTOOLS_ECLASS} ]]; then
_AUTOTOOLS_ECLASS=1
+case ${EAPI:-0} in
+ 0|1|2|3|4|5|6|7) ;;
+ *) die "${ECLASS}: EAPI ${EAPI} not supported" ;;
+esac
+
inherit libtool
# @ECLASS-VARIABLE: WANT_AUTOCONF
@@ -118,7 +124,10 @@ RDEPEND=""
# their own DEPEND string.
: ${AUTOTOOLS_AUTO_DEPEND:=yes}
if [[ ${AUTOTOOLS_AUTO_DEPEND} != "no" ]] ; then
- DEPEND=${AUTOTOOLS_DEPEND}
+ case ${EAPI:-0} in
+ 0|1|2|3|4|5|6) DEPEND=${AUTOTOOLS_DEPEND} ;;
+ 7) BDEPEND=${AUTOTOOLS_DEPEND} ;;
+ esac
fi
__AUTOTOOLS_AUTO_DEPEND=${AUTOTOOLS_AUTO_DEPEND} # See top of eclass
diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
index 3f9fd205c4..cdd63219de 100644
--- a/eclass/flag-o-matic.eclass
+++ b/eclass/flag-o-matic.eclass
@@ -34,6 +34,9 @@ setup-allowed-flags() {
# CPPFLAGS and LDFLAGS
'-[DUILR]*' '-Wl,*'
+
+ # Linker choice flag
+ '-fuse-ld'
)
# allow a bunch of flags that negate features / control ABI
@@ -595,11 +598,6 @@ get-flag() {
return 1
}
-# @FUNCTION: has_m64
-# @DESCRIPTION:
-# This doesn't test if the flag is accepted, it tests if the flag actually
-# WORKS. Non-multilib gcc will take both -m32 and -m64. If the flag works
-# return code is 0, else the return code is 1.
has_m64() {
die "${FUNCNAME}: don't use this anymore"
}
diff --git a/eclass/gnuconfig.eclass b/eclass/gnuconfig.eclass
deleted file mode 100644
index 3c8d98d6a9..0000000000
--- a/eclass/gnuconfig.eclass
+++ /dev/null
@@ -1,99 +0,0 @@
-# Copyright 1999-2012 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-#
-# THIS ECLASS IS DEAD: It has been integrated into portage
-#
-# Author: Will Woods <wwoods@gentoo.org>
-#
-# This eclass is used to automatically update files that typically come with
-# automake to the newest version available on the system. The most common use
-# of this is to update config.guess and config.sub when configure dies from
-# misguessing your canonical system name (CHOST). It can also be used to update
-# other files that come with automake, e.g. depcomp, mkinstalldirs, etc.
-#
-# usage: gnuconfig_update [file1 file2 ...]
-# if called without arguments, config.guess and config.sub will be updated.
-# All files in the source tree ($S) with the given name(s) will be replaced
-# with the newest available versions chosen from the list of locations in
-# gnuconfig_findnewest(), below.
-#
-# gnuconfig_update should generally be called from src_unpack()
-
-
-DEPEND="sys-devel/gnuconfig"
-
-# Wrapper function for gnuconfig_do_update. If no arguments are given, update
-# config.sub and config.guess (old default behavior), otherwise update the
-# named files.
-gnuconfig_update() {
-
-# hmm some packages (like binutils gcc glibc) still use this ...
-# echo
-# ewarn "QA Notice: Please stop using me, portage updates files for you."
-# echo
-
- local startdir # declared here ... used in gnuconfig_do_update
-
- if [[ $1 == /* ]] ; then
- startdir=$1
- shift
- else
- startdir=${S}
- fi
-
- if [[ $# -gt 0 ]] ; then
- gnuconfig_do_update "$@"
- else
- gnuconfig_do_update config.sub config.guess
- fi
-
- return $?
-}
-
-# Copy the newest available version of specified files over any old ones in the
-# source dir. This function shouldn't be called directly - use gnuconfig_update
-#
-# Note that since bash using dynamic scoping, startdir is available here from
-# the gnuconfig_update function
-gnuconfig_do_update() {
- local configsubs_dir target targetlist file
-
- [[ $# -eq 0 ]] && die "do not call gnuconfig_do_update; use gnuconfig_update"
-
- configsubs_dir=$(gnuconfig_findnewest)
- einfo "Using GNU config files from ${configsubs_dir}"
- for file in "$@" ; do
- if [[ ! -r ${configsubs_dir}/${file} ]] ; then
- eerror "Can't read ${configsubs_dir}/${file}, skipping.."
- continue
- fi
- targetlist=$(find "${startdir}" -name "${file}")
- if [[ -n ${targetlist} ]] ; then
- for target in ${targetlist} ; do
- [[ -L ${target} ]] && rm -f "${target}"
- einfo " Updating ${target/$startdir\//}"
- cp -f "${configsubs_dir}/${file}" "${target}"
- eend $?
- done
- else
- ewarn " No ${file} found in ${startdir}, skipping ..."
- fi
- done
-
- return 0
-}
-
-# this searches the standard locations for the newest config.{sub|guess}, and
-# returns the directory where they can be found.
-gnuconfig_findnewest() {
- has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
- local locations=(
- "${EPREFIX}"/usr/share/misc/config.sub
- "${EPREFIX}"/usr/share/gnuconfig/config.sub
- "${EPREFIX}"/usr/share/automake*/config.sub
- "${EPREFIX}"/usr/share/libtool/config.sub
- )
- grep -s '^timestamp' "${locations[@]}" | \
- sort -r -n -t\' -k2 | \
- sed -n '1{s,/config.sub:.*$,,;p;q}'
-}
diff --git a/eclass/java-utils-2.eclass b/eclass/java-utils-2.eclass
index 31ba721003..da96e04c14 100644
--- a/eclass/java-utils-2.eclass
+++ b/eclass/java-utils-2.eclass
@@ -1,4 +1,4 @@
-# Copyright 2004-2017 Gentoo Foundation
+# Copyright 2004-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: java-utils-2.eclass
@@ -23,16 +23,7 @@ IUSE="elibc_FreeBSD"
export WANT_JAVA_CONFIG="2"
# Prefix variables are only available for EAPI>=3
-# PREFIX: we always need EPREFIX, as there's still old ebuilds
-#has "${EAPI:-0}" 0 1 2 && ED="${D}" EPREFIX= EROOT="${ROOT}"
-
-# @VARIABLE: JAVA_PKG_PORTAGE_DEP
-# @INTERNAL
-# @DESCRIPTION:
-# The version of portage we need to function properly. Previously it was
-# portage with phase hooks support but now we use a version with proper env
-# saving. For EAPI 2 we have new enough stuff so let's have cleaner deps.
-has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
+has "${EAPI:-0}" 0 1 2 && ED="${D}" EPREFIX= EROOT="${ROOT}"
# @VARIABLE: JAVA_PKG_E_DEPEND
# @INTERNAL
@@ -40,7 +31,7 @@ has "${EAPI}" 0 1 && JAVA_PKG_PORTAGE_DEP=">=sys-apps/portage-2.1.2.7"
# This is a convience variable to be used from the other java eclasses. This is
# the version of java-config we want to use. Usually the latest stable version
# so that ebuilds can use new features without depending on specific versions.
-JAVA_PKG_E_DEPEND="!x86-winnt? ( >=dev-java/java-config-2.2.0-r3 ${JAVA_PKG_PORTAGE_DEP} )"
+JAVA_PKG_E_DEPEND=">=dev-java/java-config-2.2.0-r3"
has source ${JAVA_PKG_IUSE} && JAVA_PKG_E_DEPEND="${JAVA_PKG_E_DEPEND} source? ( app-arch/zip )"
# @ECLASS-VARIABLE: JAVA_PKG_WANT_BOOTCLASSPATH
@@ -1481,7 +1472,7 @@ java-pkg_ensure-vm-version-sufficient() {
if ! java-pkg_is-vm-version-sufficient; then
debug-print "VM is not suffient"
eerror "Current Java VM cannot build this package"
- einfo "Please use java-config -S to set the correct one"
+ einfo "Please use \"eselect java-vm set system\" to set the correct one"
die "Active Java VM cannot build this package"
fi
}
@@ -1509,7 +1500,7 @@ java-pkg_ensure-vm-version-eq() {
if ! java-pkg_is-vm-version-eq $@ ; then
debug-print "VM is not suffient"
eerror "This package requires a Java VM version = $@"
- einfo "Please use java-config -S to set the correct one"
+ einfo "Please use \"eselect java-vm set system\" to set the correct one"
die "Active Java VM too old"
fi
}
@@ -1556,7 +1547,7 @@ java-pkg_ensure-vm-version-ge() {
if ! java-pkg_is-vm-version-ge "$@" ; then
debug-print "vm is not suffient"
eerror "This package requires a Java VM version >= $@"
- einfo "Please use java-config -S to set the correct one"
+ einfo "Please use \"eselect java-vm set system\" to set the correct one"
die "Active Java VM too old"
fi
}
@@ -2916,7 +2907,7 @@ java-pkg_gen-cp() {
local atom
for atom in ${CP_DEPEND}; do
- if [[ ${atom} =~ /(([[:alnum:]+_-]+)-[0-9]+(\.[0-9]+)*[a-z]?(_[[:alnum:]]+)?(-r[0-9]*)?|[[:alnum:]+_-]+):([[:alnum:]+_.-]+) ]]; then
+ if [[ ${atom} =~ /(([[:alnum:]+_-]+)-[0-9]+(\.[0-9]+)*[a-z]?(_[[:alnum:]]+)*(-r[0-9]*)?|[[:alnum:]+_-]+):([[:alnum:]+_.-]+) ]]; then
atom=${BASH_REMATCH[2]:-${BASH_REMATCH[1]}}
[[ ${BASH_REMATCH[6]} != 0 ]] && atom+=-${BASH_REMATCH[6]}
local regex="(^|\s|,)${atom}($|\s|,)"
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index ebcced39bf..d72329b30a 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -7,6 +7,7 @@
# @AUTHOR:
# Author: Michał Górny <mgorny@gentoo.org>
# Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
+# @SUPPORTED_EAPIS: 0 1 2 3 4 5 6 7
# @BLURB: Utility functions for packages with Python parts.
# @DESCRIPTION:
# A utility eclass providing functions to query Python implementations,
diff --git a/eclass/toolchain-binutils.eclass b/eclass/toolchain-binutils.eclass
index 095e5d196a..6e3a60f357 100644
--- a/eclass/toolchain-binutils.eclass
+++ b/eclass/toolchain-binutils.eclass
@@ -2,6 +2,7 @@
# Distributed under the terms of the GNU General Public License v2
#
# Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
+# @SUPPORTED_EAPIS: 0 1 2 3 4 5
#
# We install binutils into CTARGET-VERSION specific directories. This lets
# us easily merge multiple versions for multiple targets (if we wish) and
@@ -15,7 +16,6 @@ if [[ -n ${BINUTILS_TYPE} ]] ; then
BTYPE=${BINUTILS_TYPE}
else
case ${PV} in
- 9999) BTYPE="git";;
9999_pre*) BTYPE="snap";;
*.*.90) BTYPE="snap";;
*.*.*.*.*) BTYPE="hjlu";;
@@ -24,11 +24,6 @@ else
fi
case ${BTYPE} in
-git)
- BVER="git"
- EGIT_REPO_URI="git://sourceware.org/git/binutils-gdb.git"
- inherit git-2
- ;;
snap)
BVER=${PV/9999_pre}
;;
@@ -58,7 +53,6 @@ DESCRIPTION="Tools necessary to build programs"
HOMEPAGE="https://sourceware.org/binutils/"
case ${BTYPE} in
- git) SRC_URI="" ;;
snap)
SRC_URI="ftp://gcc.gnu.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2
ftp://sourceware.org/pub/binutils/snapshots/binutils-${BVER}.tar.bz2" ;;
@@ -112,11 +106,7 @@ if is_cross ; then
DEPEND+=" >=sys-libs/binutils-libs-${PV}"
fi
-S=${WORKDIR}/binutils
-case ${BVER} in
-git) ;;
-*) S=${S}-${BVER} ;;
-esac
+S=${WORKDIR}/binutils-${BVER}
LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${BVER}
INCPATH=${LIBPATH}/include
@@ -129,10 +119,7 @@ else
fi
tc-binutils_unpack() {
- case ${BTYPE} in
- git) git-2_src_unpack ;;
- *) unpacker ${A} ;;
- esac
+ unpacker ${A}
mkdir -p "${MY_BUILDDIR}"
[[ -d ${WORKDIR}/patch ]] && mkdir "${WORKDIR}"/patch/skip
}
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index 14d7aea8b4..7b82db8e40 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -167,6 +167,17 @@ tc-getBUILD_OBJCOPY() { tc-getBUILD_PROG OBJCOPY objcopy "$@"; }
# @RETURN: name of the pkg-config tool for building binaries to run on the build machine
tc-getBUILD_PKG_CONFIG() { tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"; }
+# @FUNCTION: tc-getTARGET_CPP
+# @USAGE: [toolchain prefix]
+# @RETURN: name of the C preprocessor for the toolchain being built (or used)
+tc-getTARGET_CPP() {
+ if [[ -n ${CTARGET} ]]; then
+ _tc-getPROG CTARGET TARGET_CPP "gcc -E" "$@"
+ else
+ tc-getCPP "$@"
+ fi
+}
+
# @FUNCTION: tc-export
# @USAGE: <list of toolchain variables>
# @DESCRIPTION:
@@ -185,6 +196,93 @@ tc-is-cross-compiler() {
[[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
}
+# @FUNCTION: tc-cpp-is-true
+# @USAGE: <condition> [cpp flags]
+# @RETURN: Shell true if the condition is true, shell false otherwise.
+# @DESCRIPTION:
+# Evaluate the given condition using the C preprocessor for CTARGET, if
+# defined, or CHOST. Additional arguments are passed through to the cpp
+# command. A typical condition would be in the form defined(__FOO__).
+tc-cpp-is-true() {
+ local CONDITION=${1}
+ shift
+
+ local RESULT=$($(tc-getTARGET_CPP) "${@}" -P - <<-EOF 2>/dev/null
+ #if ${CONDITION}
+ true
+ #endif
+ EOF
+ )
+
+ [[ ${RESULT} == true ]]
+}
+
+# @FUNCTION: tc-detect-is-softfloat
+# @RETURN:
+# Shell true if (positive or negative) detection was possible, shell
+# false otherwise. Also outputs a string when detection succeeds, see
+# tc-is-softfloat for the possible values.
+# @DESCRIPTION:
+# Detect whether the CTARGET (or CHOST) toolchain is a softfloat based
+# one by examining the toolchain's output, if possible.
+tc-detect-is-softfloat() {
+ # If fetching CPP falls back to the default (gcc -E) then fail
+ # detection as this may not be the correct toolchain.
+ [[ $(tc-getTARGET_CPP) == "gcc -E" ]] && return 1
+
+ case ${CTARGET:-${CHOST}} in
+ # Avoid autodetection for bare-metal targets. bug #666896
+ *-newlib|*-elf|*-eabi)
+ return 1 ;;
+
+ # arm-unknown-linux-gnueabi is ambiguous. We used to treat it as
+ # hardfloat but we now treat it as softfloat like most everyone
+ # else. Check existing toolchains to respect existing systems.
+ arm*)
+ if tc-cpp-is-true "defined(__ARM_PCS_VFP)"; then
+ echo "no"
+ else
+ # Confusingly __SOFTFP__ is defined only when
+ # -mfloat-abi is soft, not softfp.
+ if tc-cpp-is-true "defined(__SOFTFP__)"; then
+ echo "yes"
+ else
+ echo "softfp"
+ fi
+ fi
+
+ return 0 ;;
+ *)
+ return 1 ;;
+ esac
+}
+
+# @FUNCTION: tc-tuple-is-softfloat
+# @RETURN: See tc-is-softfloat for the possible values.
+# @DESCRIPTION:
+# Determine whether the CTARGET (or CHOST) toolchain is a softfloat
+# based one solely from the tuple.
+tc-tuple-is-softfloat() {
+ local CTARGET=${CTARGET:-${CHOST}}
+ case ${CTARGET//_/-} in
+ bfin*|h8300*)
+ echo "only" ;;
+ *-softfloat-*)
+ echo "yes" ;;
+ *-softfp-*)
+ echo "softfp" ;;
+ arm*-hardfloat-*|arm*eabihf)
+ echo "no" ;;
+ # bare-metal targets have their defaults. bug #666896
+ *-newlib|*-elf|*-eabi)
+ echo "no" ;;
+ arm*)
+ echo "yes" ;;
+ *)
+ echo "no" ;;
+ esac
+}
+
# @FUNCTION: tc-is-softfloat
# @DESCRIPTION:
# See if this toolchain is a softfloat based one.
@@ -199,20 +297,7 @@ tc-is-cross-compiler() {
# softfloat flags in the case where support is optional, but
# rejects softfloat flags where the target always lacks an fpu.
tc-is-softfloat() {
- local CTARGET=${CTARGET:-${CHOST}}
- case ${CTARGET} in
- bfin*|h8300*)
- echo "only" ;;
- *)
- if [[ ${CTARGET//_/-} == *-softfloat-* ]] ; then
- echo "yes"
- elif [[ ${CTARGET//_/-} == *-softfp-* ]] ; then
- echo "softfp"
- else
- echo "no"
- fi
- ;;
- esac
+ tc-detect-is-softfloat || tc-tuple-is-softfloat
}
# @FUNCTION: tc-is-static-only
@@ -856,13 +941,7 @@ gcc-specs-stack-check() {
# Return truth if the current compiler generates position-independent code (PIC)
# which can be linked into executables.
tc-enables-pie() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__PIE__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
}
# @FUNCTION: tc-enables-ssp
@@ -874,13 +953,7 @@ tc-enables-pie() {
# -fstack-protector-strong
# -fstack-protector-all
tc-enables-ssp() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
}
# @FUNCTION: tc-enables-ssp-strong
@@ -891,13 +964,7 @@ tc-enables-ssp() {
# -fstack-protector-strong
# -fstack-protector-all
tc-enables-ssp-strong() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__SSP_STRONG__) || defined(__SSP_ALL__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
}
# @FUNCTION: tc-enables-ssp-all
@@ -907,13 +974,7 @@ tc-enables-ssp-strong() {
# on level corresponding to any of the following options:
# -fstack-protector-all
tc-enables-ssp-all() {
- local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
- #if defined(__SSP_ALL__)
- true
- #endif
- EOF
- )"
- [[ ${ret} == true ]]
+ tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
}
diff --git a/eclass/user.eclass b/eclass/user.eclass
deleted file mode 100644
index 83f13f25f4..0000000000
--- a/eclass/user.eclass
+++ /dev/null
@@ -1,469 +0,0 @@
-# Copyright 1999-2017 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-# @ECLASS: user.eclass
-# @MAINTAINER:
-# base-system@gentoo.org (Linux)
-# @BLURB: user management in ebuilds
-# @DESCRIPTION:
-# The user eclass contains a suite of functions that allow ebuilds
-# to quickly make sure users in the installed system are sane.
-
-if [[ -z ${_USER_ECLASS} ]]; then
-_USER_ECLASS=1
-
-# @FUNCTION: _assert_pkg_ebuild_phase
-# @INTERNAL
-# @USAGE: <calling func name>
-_assert_pkg_ebuild_phase() {
- case ${EBUILD_PHASE} in
- setup|preinst|postinst) ;;
- *)
- eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:"
- eerror "You may only call from pkg_{setup,preinst,postinst} functions."
- eerror "Package fails at QA and at life. Please file a bug."
- die "Bad package! $1 is only for use in some pkg_* functions!"
- esac
-}
-
-# @FUNCTION: egetent
-# @USAGE: <database> <key>
-# @DESCRIPTION:
-# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5),
-# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup().
-#
-# Supported databases: group passwd
-egetent() {
- local db=$1 key=$2
-
- [[ $# -ge 3 ]] && die "usage: egetent <database> <key>"
-
- case ${db} in
- passwd|group) ;;
- *) die "sorry, database '${db}' not yet supported; file a bug" ;;
- esac
-
- case ${CHOST} in
- *-darwin[678])
- case ${key} in
- *[!0-9]*) # Non numeric
- nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
- ;;
- *) # Numeric
- nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
- ;;
- esac
- ;;
- *-darwin*)
- local mykey
- case ${db} in
- passwd) db="Users" mykey="UniqueID" ;;
- group) db="Groups" mykey="PrimaryGroupID" ;;
- esac
-
- case ${key} in
- *[!0-9]*) # Non numeric
- dscl . -read /${db}/${key} 2>/dev/null |grep RecordName
- ;;
- *) # Numeric
- dscl . -search /${db} ${mykey} ${key} 2>/dev/null
- ;;
- esac
- ;;
- *-freebsd*|*-dragonfly*)
- case ${db} in
- passwd) db="user" ;;
- *) ;;
- esac
-
- # lookup by uid/gid
- local opts
- if [[ ${key} == [[:digit:]]* ]] ; then
- [[ ${db} == "user" ]] && opts="-u" || opts="-g"
- fi
-
- pw show ${db} ${opts} "${key}" -q
- ;;
- *-netbsd*|*-openbsd*)
- grep "${key}:\*:" /etc/${db}
- ;;
- *)
- # ignore output if nscd doesn't exist, or we're not running as root
- nscd -i "${db}" 2>/dev/null
- getent "${db}" "${key}"
- ;;
- esac
-}
-
-# @FUNCTION: enewuser
-# @USAGE: <user> [uid] [shell] [homedir] [groups]
-# @DESCRIPTION:
-# Same as enewgroup, you are not required to understand how to properly add
-# a user to the system. The only required parameter is the username.
-# Default uid is (pass -1 for this) next available, default shell is
-# /bin/false, default homedir is /dev/null, and there are no default groups.
-enewuser() {
- if [[ ${EUID} != 0 ]] ; then
- einfo "Insufficient privileges to execute ${FUNCNAME[0]}"
- return 0
- fi
- _assert_pkg_ebuild_phase ${FUNCNAME}
-
- # get the username
- local euser=$1; shift
- if [[ -z ${euser} ]] ; then
- eerror "No username specified !"
- die "Cannot call enewuser without a username"
- fi
-
- # lets see if the username already exists
- if [[ -n $(egetent passwd "${euser}") ]] ; then
- return 0
- fi
- einfo "Adding user '${euser}' to your system ..."
-
- # options to pass to useradd
- local opts=()
-
- # handle uid
- local euid=$1; shift
- if [[ -n ${euid} && ${euid} != -1 ]] ; then
- if [[ ${euid} -gt 0 ]] ; then
- if [[ -n $(egetent passwd ${euid}) ]] ; then
- euid="next"
- fi
- else
- eerror "Userid given but is not greater than 0 !"
- die "${euid} is not a valid UID"
- fi
- else
- euid="next"
- fi
- if [[ ${euid} == "next" ]] ; then
- for ((euid = 101; euid <= 999; euid++)); do
- [[ -z $(egetent passwd ${euid}) ]] && break
- done
- fi
- opts+=( -u ${euid} )
- einfo " - Userid: ${euid}"
-
- # handle shell
- local eshell=$1; shift
- if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then
- if [[ ! -e ${EROOT}${eshell} ]] ; then
- eerror "A shell was specified but it does not exist !"
- die "${eshell} does not exist in ${EROOT}"
- fi
- if [[ ${eshell} == */false || ${eshell} == */nologin ]] ; then
- eerror "Do not specify ${eshell} yourself, use -1"
- die "Pass '-1' as the shell parameter"
- fi
- else
- for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do
- [[ -x ${ROOT}${eshell} ]] && break
- done
-
- if [[ ${eshell} == "/dev/null" ]] ; then
- eerror "Unable to identify the shell to use, proceeding with userland default."
- case ${USERLAND} in
- GNU) eshell="/bin/false" ;;
- BSD) eshell="/sbin/nologin" ;;
- Darwin) eshell="/usr/sbin/nologin" ;;
- *) die "Unable to identify the default shell for userland ${USERLAND}"
- esac
- fi
- fi
- einfo " - Shell: ${eshell}"
- opts+=( -s "${eshell}" )
-
- # handle homedir
- local ehome=$1; shift
- if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
- ehome="/dev/null"
- fi
- einfo " - Home: ${ehome}"
- opts+=( -d "${ehome}" )
-
- # handle groups
- local egroups=$1; shift
- local g egroups_arr
- IFS="," read -r -a egroups_arr <<<"${egroups}"
- if [[ ${#egroups_arr[@]} -gt 0 ]] ; then
- local defgroup exgroups
- for g in "${egroups_arr[@]}" ; do
- if [[ -z $(egetent group "${g}") ]] ; then
- eerror "You must add group ${g} to the system first"
- die "${g} is not a valid GID"
- fi
- if [[ -z ${defgroup} ]] ; then
- defgroup=${g}
- else
- exgroups+=",${g}"
- fi
- done
- opts+=( -g "${defgroup}" )
- if [[ ! -z ${exgroups} ]] ; then
- opts+=( -G "${exgroups:1}" )
- fi
- fi
- einfo " - Groups: ${egroups:-(none)}"
-
- # handle extra args
- if [[ $# -gt 0 ]] ; then
- die "extra arguments no longer supported; please file a bug"
- else
- local comment="added by portage for ${PN}"
- opts+=( -c "${comment}" )
- einfo " - GECOS: ${comment}"
- fi
-
- # add the user
- case ${CHOST} in
- *-darwin*)
- ### Make the user
- dscl . create "/users/${euser}" uid ${euid}
- dscl . create "/users/${euser}" shell "${eshell}"
- dscl . create "/users/${euser}" home "${ehome}"
- dscl . create "/users/${euser}" realname "added by portage for ${PN}"
- ### Add the user to the groups specified
- for g in "${egroups_arr[@]}" ; do
- dscl . merge "/groups/${g}" users "${euser}"
- done
- ;;
-
- *-freebsd*|*-dragonfly*)
- pw useradd "${euser}" "${opts[@]}" || die
- ;;
-
- *-netbsd*)
- useradd "${opts[@]}" "${euser}" || die
- ;;
-
- *-openbsd*)
- # all ops the same, except the -g vs -g/-G ...
- useradd -u ${euid} -s "${eshell}" \
- -d "${ehome}" -g "${egroups}" "${euser}" || die
- ;;
-
- *)
- useradd -r "${opts[@]}" "${euser}" || die
- ;;
- esac
-
- if [[ ! -e ${EROOT}/${ehome} ]] ; then
- einfo " - Creating ${ehome} in ${EROOT}"
- mkdir -p "${EROOT}/${ehome}"
- chown "${euser}" "${EROOT}/${ehome}"
- chmod 755 "${EROOT}/${ehome}"
- fi
-}
-
-# @FUNCTION: enewgroup
-# @USAGE: <group> [gid]
-# @DESCRIPTION:
-# This function does not require you to understand how to properly add a
-# group to the system. Just give it a group name to add and enewgroup will
-# do the rest. You may specify the gid for the group or allow the group to
-# allocate the next available one.
-enewgroup() {
- if [[ ${EUID} != 0 ]] ; then
- einfo "Insufficient privileges to execute ${FUNCNAME[0]}"
- return 0
- fi
- _assert_pkg_ebuild_phase ${FUNCNAME}
-
- # get the group
- local egroup=$1; shift
- if [[ -z ${egroup} ]] ; then
- eerror "No group specified !"
- die "Cannot call enewgroup without a group"
- fi
-
- # see if group already exists
- if [[ -n $(egetent group "${egroup}") ]] ; then
- return 0
- fi
- einfo "Adding group '${egroup}' to your system ..."
-
- # handle gid
- local egid=$1; shift
- if [[ ! -z ${egid} ]] ; then
- if [[ ${egid} -gt 0 ]] ; then
- if [[ -n $(egetent group ${egid}) ]] ; then
- egid="next available; requested gid taken"
- fi
- else
- eerror "Groupid given but is not greater than 0 !"
- die "${egid} is not a valid GID"
- fi
- else
- egid="next available"
- fi
- einfo " - Groupid: ${egid}"
-
- # handle extra
- if [[ $# -gt 0 ]] ; then
- die "extra arguments no longer supported; please file a bug"
- fi
-
- # Some targets need to find the next available GID manually
- _enewgroup_next_gid() {
- if [[ ${egid} == *[!0-9]* ]] ; then
- # Non numeric
- for ((egid = 101; egid <= 999; egid++)) ; do
- [[ -z $(egetent group ${egid}) ]] && break
- done
- fi
- }
-
- # add the group
- case ${CHOST} in
- *-darwin*)
- _enewgroup_next_gid
- dscl . create "/groups/${egroup}" gid ${egid}
- dscl . create "/groups/${egroup}" passwd '*'
- ;;
-
- *-freebsd*|*-dragonfly*)
- _enewgroup_next_gid
- pw groupadd "${egroup}" -g ${egid} || die
- ;;
-
- *-netbsd*)
- _enewgroup_next_gid
- groupadd -g ${egid} "${egroup}" || die
- ;;
-
- *)
- local opts
- if [[ ${egid} == *[!0-9]* ]] ; then
- # Non numeric; let groupadd figure out a GID for us
- opts=""
- 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
- ;;
- esac
-}
-
-# @FUNCTION: egethome
-# @USAGE: <user>
-# @DESCRIPTION:
-# Gets the home directory for the specified user.
-egethome() {
- local pos
-
- [[ $# -eq 1 ]] || die "usage: egethome <user>"
-
- case ${CHOST} in
- *-darwin*|*-freebsd*|*-dragonfly*)
- pos=9
- ;;
- *) # Linux, NetBSD, OpenBSD, etc...
- pos=6
- ;;
- esac
-
- egetent passwd "$1" | cut -d: -f${pos}
-}
-
-# @FUNCTION: egetshell
-# @USAGE: <user>
-# @DESCRIPTION:
-# Gets the shell for the specified user.
-egetshell() {
- local pos
-
- [[ $# -eq 1 ]] || die "usage: egetshell <user>"
-
- case ${CHOST} in
- *-darwin*|*-freebsd*|*-dragonfly*)
- pos=10
- ;;
- *) # Linux, NetBSD, OpenBSD, etc...
- pos=7
- ;;
- esac
-
- 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
-
- # exit with no message if home dir is up to date
- if [[ $(egethome "${euser}") == ${ehome} ]]; then
- return 0
- fi
-
- einfo "Updating home for user '${euser}' ..."
- einfo " - Home: ${ehome}"
-
- # ensure home directory exists, otherwise update will fail
- if [[ ! -e ${EROOT}/${ehome} ]] ; then
- einfo " - Creating ${ehome} in ${EROOT}"
- mkdir -p "${EROOT}/${ehome}"
- chown "${euser}" "${EROOT}/${ehome}"
- chmod 755 "${EROOT}/${ehome}"
- fi
-
- # update the home directory
- case ${CHOST} in
- *-darwin*)
- dscl . change "/users/${euser}" home "${ehome}"
- ;;
-
- *-freebsd*|*-dragonfly*)
- pw usermod "${euser}" -d "${ehome}" && return 0
- [[ $? == 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:"
- eerror "\t pw usermod \"${euser}\" -d \"${ehome}\""
- ;;
-
- *)
- usermod -d "${ehome}" "${euser}" && return 0
- [[ $? == 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):"
- eerror "\t usermod -d \"${ehome}\" \"${euser}\""
- ;;
- esac
-}
-
-fi
next reply other threads:[~2018-12-17 9:55 UTC|newest]
Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-17 9:55 Fabian Groffen [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-09-30 9:08 [gentoo-commits] repo/proj/prefix:master commit in: eclass/ Fabian Groffen
2024-09-23 18:25 Fabian Groffen
2024-08-11 16:19 Fabian Groffen
2024-08-10 14:43 Fabian Groffen
2024-08-10 14:24 Fabian Groffen
2024-08-10 14:24 Fabian Groffen
2024-08-10 10:48 Fabian Groffen
2024-08-09 9:25 Fabian Groffen
2024-08-07 17:08 Fabian Groffen
2024-08-07 17:03 Fabian Groffen
2024-07-25 6:25 Fabian Groffen
2024-07-17 12:01 Fabian Groffen
2024-05-09 7:14 Fabian Groffen
2024-01-21 13:47 Fabian Groffen
2024-01-21 13:43 Fabian Groffen
2024-01-21 13:40 Fabian Groffen
2023-12-16 15:36 Fabian Groffen
2023-09-11 23:33 Sam James
2023-09-04 6:36 Fabian Groffen
2023-09-03 19:39 Fabian Groffen
2023-05-24 7:55 Fabian Groffen
2023-05-24 6:19 Fabian Groffen
2022-06-29 14:53 Sam James
2022-06-29 14:05 Sam James
2022-06-07 17:01 Fabian Groffen
2022-06-07 12:35 Fabian Groffen
2022-06-06 16:51 Fabian Groffen
2022-06-06 9:07 Fabian Groffen
2022-06-06 8:42 Fabian Groffen
2022-05-10 6:22 Fabian Groffen
2022-02-17 0:12 Sam James
2022-02-10 8:54 Fabian Groffen
2022-01-31 1:07 Sam James
2022-01-23 2:27 Sam James
2022-01-23 1:21 Sam James
2021-12-03 10:03 Fabian Groffen
2021-10-21 6:39 Fabian Groffen
2021-10-14 6:15 Sam James
2021-10-14 6:15 Sam James
2021-10-13 4:05 Sam James
2021-07-13 9:02 Fabian Groffen
2021-06-29 6:48 Fabian Groffen
2021-06-29 6:23 Fabian Groffen
2021-05-04 17:20 Fabian Groffen
2021-05-04 17:20 Fabian Groffen
2021-05-04 17:20 Fabian Groffen
2021-05-04 17:20 Fabian Groffen
2021-05-04 17:20 Fabian Groffen
2021-05-04 17:09 Fabian Groffen
2021-04-10 7:15 Sam James
2021-04-10 7:15 Sam James
2021-04-10 7:15 Sam James
2021-04-10 7:09 Sam James
2021-03-13 9:54 Fabian Groffen
2021-02-07 19:23 Fabian Groffen
2021-01-24 9:47 Fabian Groffen
2021-01-14 8:02 Fabian Groffen
2021-01-12 13:32 Fabian Groffen
2021-01-11 19:53 Fabian Groffen
2020-12-15 7:48 Fabian Groffen
2020-11-29 14:24 Fabian Groffen
2020-11-29 13:41 Fabian Groffen
2020-08-09 8:14 Fabian Groffen
2020-06-22 18:28 Fabian Groffen
2020-06-22 13:56 Fabian Groffen
2020-05-26 6:44 Fabian Groffen
2020-03-26 7:56 Fabian Groffen
2020-03-22 9:25 Fabian Groffen
2020-03-16 17:23 Michael Haubenwallner
2020-03-13 7:51 Fabian Groffen
2019-12-11 9:47 Fabian Groffen
2019-11-14 6:36 Fabian Groffen
2019-05-30 8:25 Fabian Groffen
2019-03-25 14:20 Michael Haubenwallner
2018-07-17 8:45 Fabian Groffen
2018-07-03 8:52 Michael Haubenwallner
2018-06-22 13:16 Michael Haubenwallner
2018-06-20 7:32 Fabian Groffen
2018-06-06 12:48 Fabian Groffen
2017-12-12 18:53 Fabian Groffen
2017-12-12 18:53 Fabian Groffen
2017-10-17 8:39 Fabian Groffen
2017-10-16 13:54 Fabian Groffen
2017-10-03 7:38 Michael Haubenwallner
2016-07-08 11:17 Fabian Groffen
2016-06-15 11:32 [gentoo-commits] repo/proj/prefix:rap0 " Benda XU
2016-06-15 11:05 ` [gentoo-commits] repo/proj/prefix:master " Benda XU
2016-04-18 8:07 Michael Haubenwallner
2016-03-20 18:22 Fabian Groffen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1545040525.d6ffd48fbde60f371dd8b763b9ab9a4beecf282a.grobian@gentoo \
--to=grobian@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox