# Copyright 2026 Nadeŭka # Distributed under the terms of the GNU General Public License v2 # @ECLASS: sysgroup.eclass # @MAINTAINER: # Nadeŭka # @SUPPORTED_EAPIS: 8 9 # @BLURB: Eclass used to create and maintain a single group entry # @DESCRIPTION: # Creates a single system group and installs a matching sysusers.d entry. # Works with no configuration at all: the group is named after ${PN}. # @EXAMPLE: # EAPI=8 # inherit sysgroup if [[ ! -v _SYSGROUP_ECLASS ]]; then _SYSGROUP_ECLASS=1 case ${EAPI} in 8|9) ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; esac inherit pkgvar sysidentity # @ECLASS_VARIABLE: SYSGROUP_NAME # @DESCRIPTION: # The name of the group. Defaults to ${PN}. pkgvar_declare SYSGROUP_NAME "${PN}" # @ECLASS_VARIABLE: SYSGROUP_ID # @REQUIRED # @DESCRIPTION: # Preferred GID for the new group. Defaults to -1 (dynamic allocation). pkgvar_declare SYSGROUP_ID -1 # @ECLASS_VARIABLE: SYSGROUP_ID_FORCE # @DEFAULT_UNSET # @DESCRIPTION: # If set to 1, require the group to have the exact specified GID. pkgvar_declare SYSGROUP_ID_FORCE '' # @ECLASS_VARIABLE: SYSGROUP_PASSWD_HASH # @DEFAULT_UNSET # @DESCRIPTION: # Encrypted password hash for the group. Defaults to unset. pkgvar_declare SYSGROUP_PASSWD_HASH '' : "${DESCRIPTION:="System group: ${SYSGROUP_NAME}"}" sysgroup_pkg_pretend() { debug-print-function ${FUNCNAME} "$@" sysidentity_checkid group "${SYSGROUP_NAME}" "${SYSGROUP_ID}" "${SYSGROUP_ID_FORCE}" } sysgroup_src_install() { debug-print-function ${FUNCNAME} "$@" local line printf -v line 'g\t%q\t%q' "${SYSGROUP_NAME}" "${SYSGROUP_ID/#-*/-}" [[ -z ${SYSGROUP_PASSWD_HASH} ]] || printf -v line '%s\t%q' "${line}" "${SYSGROUP_PASSWD_HASH}" sysidentity_newsysusers - "${CATEGORY}-${SYSGROUP_NAME}.conf" <<< "${line}" } sysgroup_pkg_preinst() { debug-print-function ${FUNCNAME} "$@" sysidentity_islock || return 0 sysidentity_add group "${SYSGROUP_NAME}" "${SYSGROUP_ID}" "${SYSGROUP_PASSWD_HASH}" || return 0 } fi EXPORT_FUNCTIONS pkg_pretend src_install pkg_preinst