2010-11-04 13:53:46 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
#
|
|
|
|
# (Un)registers systems accounts (users/groups).
|
|
|
|
#
|
|
|
|
# Arguments: $ACTION = [run/targets]
|
|
|
|
# $TARGET = [post-install/pre-remove]
|
|
|
|
# $PKGNAME
|
|
|
|
# $VERSION
|
|
|
|
# $UPDATE = [yes/no]
|
|
|
|
#
|
|
|
|
ACTION="$1"
|
|
|
|
TARGET="$2"
|
|
|
|
PKGNAME="$3"
|
|
|
|
VERSION="$4"
|
|
|
|
UPDATE="$5"
|
|
|
|
|
2010-12-28 11:22:58 +01:00
|
|
|
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
|
|
|
|
}
|
2010-11-04 13:53:46 +01:00
|
|
|
|
|
|
|
case "$ACTION" in
|
|
|
|
targets)
|
|
|
|
echo "post-install pre-remove"
|
|
|
|
;;
|
|
|
|
run)
|
2010-12-28 11:22:58 +01:00
|
|
|
if [ ! -x $USERADD -a ! -x $GROUPADD -a ! -x $PASSWD -a ! -x $GETENT ]; then
|
2010-11-04 13:53:46 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2010-12-28 11:22:58 +01:00
|
|
|
if [ -z "$system_accounts" -a -z "$system_groups" ]; then
|
2010-11-04 13:53:46 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$TARGET" in
|
|
|
|
post-install)
|
2010-12-28 11:22:58 +01:00
|
|
|
# System user/group required by a package.
|
2010-11-04 13:53:46 +01:00
|
|
|
for acct in ${system_accounts}; do
|
|
|
|
eval homedir="\$${acct}_homedir"
|
|
|
|
eval shell="\$${acct}_shell"
|
|
|
|
eval descr="\$${acct}_descr"
|
|
|
|
eval groups="\$${acct}_groups"
|
|
|
|
[ -z "$homedir" ] && homedir="/"
|
|
|
|
[ -z "$shell" ] && shell="/sbin/nologin"
|
|
|
|
[ -z "$descr" ] && descr="$acct unpriviledged user"
|
|
|
|
[ -n "$groups" ] && groups="-G $groups"
|
|
|
|
|
2010-12-28 11:22:58 +01:00
|
|
|
group_add $groups
|
|
|
|
|
|
|
|
if ! $GETENT passwd ${acct} >/dev/null; then
|
|
|
|
$USERADD -c "$descr" -d "$homedir" \
|
2010-11-04 13:53:46 +01:00
|
|
|
-s "$shell" -g ${acct} $groups \
|
|
|
|
-r ${acct} && \
|
2010-12-28 11:22:58 +01:00
|
|
|
$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
|
2010-11-04 13:53:46 +01:00
|
|
|
fi
|
|
|
|
done
|
2010-12-28 11:22:58 +01:00
|
|
|
|
|
|
|
# System groups required by a package.
|
|
|
|
for grp in ${system_groups}; do
|
|
|
|
group_add $grp
|
|
|
|
done
|
2010-11-04 13:53:46 +01:00
|
|
|
;;
|
|
|
|
pre-remove)
|
|
|
|
#
|
|
|
|
# Only unregister if we aren't updating a package.
|
|
|
|
#
|
|
|
|
if [ "$UPDATE" = "no" ]; then
|
|
|
|
for acct in ${system_accounts}; do
|
2010-12-28 11:22:58 +01:00
|
|
|
$USERDEL ${acct} >/dev/null 2>&1
|
2010-11-04 13:53:46 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Removed ${acct} system user/group."
|
|
|
|
fi
|
|
|
|
done
|
2010-12-28 11:22:58 +01:00
|
|
|
for grp in ${system_groups}; do
|
|
|
|
$GROUPDEL ${grp} >/dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "Removed ${grp} system group."
|
|
|
|
fi
|
|
|
|
done
|
2010-11-04 13:53:46 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|