#40 Backport macros.sysusers from Fedora/systemd
Merged 2 years ago by ngompa. Opened 2 years ago by pgreco.
rpms/ pgreco/epel-rpm-macros epel7  into  epel7

file modified
+36 -1
@@ -1,6 +1,6 @@ 

  Name:           epel-rpm-macros

  Version:        7

- Release:        34

+ Release:        35

  Summary:        Extra Packages for Enterprise Linux RPM macros

  

  Group:          System Environment/Base
@@ -14,6 +14,13 @@ 

  Source1:        macros.zzz-epel-override

  Source2:        gpgverify

  Source9:        GPL

+ 

+ # sysusers https://src.fedoraproject.org/rpms/systemd/c/ced9237a14d6775a98e1a2f93880990417b4ae6e

+ Source21:       macros.sysusers

+ Source22:       sysusers.attr

+ Source23:       sysusers.prov

+ Source24:       sysusers.generate-pre.sh

+ 

  # misc macros

  Source150:      macros.build-constraints

  
@@ -32,6 +39,18 @@ 

  This package contains the Extra Packages for Enterprise Linux (EPEL) RPM

  macros for building EPEL packages.

  

+ %package systemd

+ Summary:  Extra Packages for Enterprise Linux RPM macros (systemd)

+ Requires: epel-rpm-macros

+ Requires: systemd

+ 

+ #Provides systemd-rpm-macros, backported from fedora systemd

+ Provides:       systemd-rpm-macros

+ 

+ %description systemd

+ This package contains the systemd specific Extra Packages for Enterprise

+ Linux (EPEL) RPM macros for building EPEL packages.

+ 

  %prep

  %setup -cT

  install -pm 644 %{SOURCE9} .
@@ -48,6 +67,12 @@ 

  install -Dpm 755 %{SOURCE2} \

      %{buildroot}%{_rpmconfigdir}/gpgverify

  

+ # sysusers

+ mkdir -p %{buildroot}%{_rpmconfigdir}/fileattrs/

+ install -Dpm 0644 %{SOURCE21} %{buildroot}%{_rpmconfigdir}/macros.d/

+ install -Dpm 0644 %{SOURCE22} %{buildroot}%{_rpmconfigdir}/fileattrs/

+ install -Dpm 0755 %{SOURCE23} %{buildroot}%{_rpmconfigdir}/

+ install -Dpm 0755 %{SOURCE24} %{buildroot}%{_rpmconfigdir}/

  # misc macros

  install -Dpm 644 %{SOURCE150} \

      %{buildroot}%{_rpmconfigdir}/macros.d/macros.build-constraints
@@ -57,11 +82,21 @@ 

  %{_rpmconfigdir}/macros.d/macros.epel-rpm-macros

  %{_sysconfdir}/rpm/macros.zzz-epel-override

  %{_rpmconfigdir}/gpgverify

+ 

  # misc macros

  %{_rpmconfigdir}/macros.d/macros.build-constraints

  

+ %files systemd

+ # sysusers

+ %{_rpmconfigdir}/macros.d/macros.sysusers

+ %{_rpmconfigdir}/fileattrs/sysusers.attr

+ %{_rpmconfigdir}/sysusers.prov

+ %{_rpmconfigdir}/sysusers.generate-pre.sh

  

  %changelog

+ * Wed Jan 31 2022 Pablo Greco <pgreco@centosproject.org> - 7-35

+ - Backport systemd sysusers macros from Fedora

+ 

  * Mon Jan 31 2022 Stephen Gallagher <sgallagh@redhat.com> - 7-34

  - Drop nodejs_arches override. RHEL now provides all of the arches.

  

file added
+10
@@ -0,0 +1,10 @@ 

+ # RPM macros for packages creating system accounts

+ #

+ # Turn a sysusers.d file into macros specified by

+ # https://docs.fedoraproject.org/en-US/packaging-guidelines/UsersAndGroups/#_dynamic_allocation

+ 

+ %sysusers_requires_compat Requires(pre): shadow-utils

+ 

+ %sysusers_create_compat() \

+ %(%{_rpmconfigdir}/sysusers.generate-pre.sh %{?*}) \

+ %{nil}

file added
+2
@@ -0,0 +1,2 @@ 

+ %__sysusers_provides	%{_rpmconfigdir}/sysusers.prov

+ %__sysusers_path	^%{_sysusersdir}/.*\\.conf$

@@ -0,0 +1,79 @@ 

+ #!/bin/bash

+ 

+ # This script turns sysuser.d files into scriptlets mandated by Fedora

+ # packaging guidelines. The general idea is to define users using the

+ # declarative syntax but to turn this into traditional scriptlets.

+ 

+ user() {

+     user="$1"

+     uid="$2"

+     desc="$3"

+     group="$4"

+     home="$5"

+     shell="$6"

+ 

+     [ "$desc" = '-' ] && desc=

+     { [ "$home" = '-' ] || [ "$home" = '' ]; } && home=/

+     { [ "$shell" = '-' ] || [ "$shell" = '' ]; } && shell=/sbin/nologin

+ 

+     if [ "$uid" = '-' ] || [ "$uid" = '' ]; then

+         cat <<EOF

+ getent passwd '$user' >/dev/null || \\

+     useradd -r -g '$group' -d '$home' -s '$shell' -c '$desc' '$user'

+ EOF

+     else

+         cat <<EOF

+ if ! getent passwd '$user' >/dev/null ; then

+     if ! getent passwd '$uid' >/dev/null ; then

+         useradd -r -u '$uid' -g '$group' -d '$home' -s /sbin/nologin -c '$desc' '$user'

+     else

+         useradd -r -g '$group' -d '$home' -s /sbin/nologin -c '$desc' '$user'

+     fi

+ fi

+ 

+ EOF

+     fi

+ }

+ 

+ group() {

+     group="$1"

+     gid="$2"

+     if [ "$gid" = '-' ]; then

+         cat <<-EOF

+ 	getent group '$group' >/dev/null || groupadd -r '$group'

+ 	EOF

+     else

+         cat <<-EOF

+ 	getent group '$group' >/dev/null || groupadd -f -g '$gid' -r '$group'

+ 	EOF

+     fi

+ }

+ 

+ parse() {

+     while read -r line || [ -n "$line" ] ; do

+         { [ "${line:0:1}" = '#' ] || [ "${line:0:1}" = ';' ]; } && continue

+         line="${line## *}"

+         [ -z "$line" ] && continue

+         eval "arr=( $line )"

+         case "${arr[0]}" in

+             ('u')

+                 group "${arr[1]}" "${arr[2]}"

+                 user "${arr[1]}" "${arr[2]}" "${arr[3]}" "${arr[1]}" "${arr[4]}" "${arr[5]}"

+                 # TODO: user:group support

+                 ;;

+             ('g')

+                 group "${arr[1]}" "${arr[2]}"

+                 ;;

+             ('m')

+                 group "${arr[2]}" "-"

+                 user "${arr[1]}" "-" "" "${arr[2]}"

+                 ;;

+         esac

+     done

+ }

+ 

+ for fn in "$@"; do

+     [ -e "$fn" ] || continue

+     echo "# generated from $(basename "$fn")"

+     parse <"$fn"

+ done

file added
+28
@@ -0,0 +1,28 @@ 

+ #!/bin/bash

+ 

+ parse() {

+     while read line; do

+         [ "${line:0:1}" = '#' -o "${line:0:1}" = ';' ] && continue

+         line="${line## *}"

+         [ -z "$line" ] && continue

+         set -- $line

+         case "$1" in

+             ('u')

+                 echo "user($2)"

+                 echo "group($2)"

+                 # TODO: user:group support

+                 ;;

+             ('g')

+                 echo "group($2)"

+                 ;;

+             ('m')

+                 echo "user($2)"

+                 echo "group($3)"

+                 ;;

+         esac

+     done

+ }

+ 

+ while read fn; do

+     parse < "$fn"

+ done

no initial comment

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.

rebased onto 0de763d913fcc9fbd6643146fe68c29c627a22e3

2 years ago

We should introduce a subpackage that pulls in systemd and includes these macros (and has the provides). Probably systemd-epel-rpm-macros or epel-rpm-macros-systemd? Otherwise we'll only have half the macros for systemd macros for packages that BR systemd-rpm-macros.

rebased onto 95e973b0b39e164bfc4db52d4bc39b52fd13a6fa

2 years ago

I thought we had decided to use them in the main package in epel7 for some reason. Updated now

This should be under the systemd subpackage.

rebased onto a55fc2c

2 years ago

Pull-Request has been merged by ngompa

2 years ago