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'.
This commit is contained in:
Juan RP 2010-12-28 11:22:58 +01:00
parent 51a87084e6
commit 809bb752fa
3 changed files with 58 additions and 24 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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 <xtraeme@gmail.com>"