From 809bb752faf2d6372e96d3b1e0e19e8b4b2f961f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 28 Dec 2010 11:22:58 +0100 Subject: [PATCH] xbps-triggers: improve dkms and system_accounts triggers. Bump to 0.13. dkms: check correct version module via 'dkms status'. system-accounts: it's possible now to create only system groups with 'system_groups'. --- srcpkgs/xbps-triggers/files/dkms | 14 +++-- srcpkgs/xbps-triggers/files/system-accounts | 66 +++++++++++++++------ srcpkgs/xbps-triggers/template | 2 +- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/srcpkgs/xbps-triggers/files/dkms b/srcpkgs/xbps-triggers/files/dkms index 253ec861bcc..915ed6a3bdf 100755 --- a/srcpkgs/xbps-triggers/files/dkms +++ b/srcpkgs/xbps-triggers/files/dkms @@ -22,18 +22,24 @@ DKMS=usr/sbin/dkms remove_modules() { + local ver + # Remove the specified modules from all kernels. set -- ${dkms_modules} while [ $# -gt 0 ]; do - if $DKMS status -m $1 | egrep -q '(added|built|installed)' > /dev/null; then - echo -n "Removing DKMS module '$1-$2'... " - $DKMS remove -m $1 -v $2 --all >/dev/null 2>&1 + $DKMS status -m $1 | while read line; do + if $(echo $line | egrep -vq '(added|built|installed)'); then + shift; shift; continue + fi + ver=$(echo "$line" | sed "s/$1,\([^,]*\)[,:].*/\1/;t;d") + echo -n "Removing DKMS module '$1-$ver'... " + $DKMS remove -m $1 -v $ver --all >/dev/null 2>&1 if [ $? -eq 0 ]; then echo "done." else echo "FAILED!" fi - fi + done shift; shift; done } diff --git a/srcpkgs/xbps-triggers/files/system-accounts b/srcpkgs/xbps-triggers/files/system-accounts index ec2d21da301..05d0f7be6f5 100755 --- a/srcpkgs/xbps-triggers/files/system-accounts +++ b/srcpkgs/xbps-triggers/files/system-accounts @@ -14,28 +14,44 @@ PKGNAME="$3" VERSION="$4" UPDATE="$5" -useradd_cmd=usr/sbin/useradd -userdel_cmd=usr/sbin/userdel -groupadd_cmd=usr/sbin/groupadd -passwd_cmd=usr/bin/passwd -getent_cmd=usr/bin/getent +USERADD=usr/sbin/useradd +USERDEL=usr/sbin/userdel +GROUPADD=usr/sbin/groupadd +GROUPDEL=usr/sbin/groupdel +PASSWD=usr/bin/passwd +GETENT=usr/bin/getent + +group_add() +{ + local grp="$1" + + if ! $GETENT group ${grp} >/dev/null; then + $GROUPADD -r ${grp} >/dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "Created ${grp} system group." + else + echo "Failed to create ${grp} system group!" + exit 1 + fi + fi +} case "$ACTION" in targets) echo "post-install pre-remove" ;; run) - if [ ! -x $useradd_cmd -a ! -x $groupadd_cmd -a ! -x $passwd_cmd \ - -a ! -x $getent_cmd ]; then + if [ ! -x $USERADD -a ! -x $GROUPADD -a ! -x $PASSWD -a ! -x $GETENT ]; then exit 0 fi - if [ -z "$system_accounts" ]; then + if [ -z "$system_accounts" -a -z "$system_groups" ]; then exit 0 fi case "$TARGET" in post-install) + # System user/group required by a package. for acct in ${system_accounts}; do eval homedir="\$${acct}_homedir" eval shell="\$${acct}_shell" @@ -46,20 +62,26 @@ run) [ -z "$descr" ] && descr="$acct unpriviledged user" [ -n "$groups" ] && groups="-G $groups" - if ! $getent_cmd group ${acct} >/dev/null; then - $groupadd_cmd -r ${acct} \ - 2>&1 >/dev/null || exit $? - echo "Created ${acct} system group." - fi - if ! $getent_cmd passwd ${acct} >/dev/null; then - $useradd_cmd -c "$descr" -d "$homedir" \ + group_add $groups + + if ! $GETENT passwd ${acct} >/dev/null; then + $USERADD -c "$descr" -d "$homedir" \ -s "$shell" -g ${acct} $groups \ -r ${acct} && \ - $passwd_cmd -l ${acct} \ - 2>&1 >/dev/null || exit $? - echo "Created ${acct} system user." + $PASSWD -l ${acct} >/dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "Created ${acct} system user." + else + echo "Failed to create ${acct} system user!" + exit 1 + fi fi done + + # System groups required by a package. + for grp in ${system_groups}; do + group_add $grp + done ;; pre-remove) # @@ -67,11 +89,17 @@ run) # if [ "$UPDATE" = "no" ]; then for acct in ${system_accounts}; do - $userdel_cmd ${acct} 2>&1 >/dev/null + $USERDEL ${acct} >/dev/null 2>&1 if [ $? -eq 0 ]; then echo "Removed ${acct} system user/group." fi done + for grp in ${system_groups}; do + $GROUPDEL ${grp} >/dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "Removed ${grp} system group." + fi + done fi ;; esac diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template index 4d7e7777260..87e33796cb1 100644 --- a/srcpkgs/xbps-triggers/template +++ b/srcpkgs/xbps-triggers/template @@ -1,6 +1,6 @@ # Template file for 'xbps-triggers' pkgname=xbps-triggers -version=0.12 +version=0.13 build_style=custom-install short_desc="XBPS triggers" maintainer="Juan RP "