Add a trigger to (un)register system user/groups.
The following vars can be used for this: - system_accounts="foo blah" - foo_homedir, foo_shell, foo_descr, foo_groups. --HG-- extra : convert_revision : bc7d002e00abc5c84f83a3716a8ecf97f9c9ff24
This commit is contained in:
parent
af1b82c40a
commit
4c2cc8b588
1
TODO
1
TODO
|
@ -3,4 +3,3 @@
|
||||||
- Use binary pkgs for required build dependencies.
|
- Use binary pkgs for required build dependencies.
|
||||||
- Make src packages self contained, without requiring to download
|
- Make src packages self contained, without requiring to download
|
||||||
the whole repository.
|
the whole repository.
|
||||||
- Add a trigger to (un)register system user/groups.
|
|
||||||
|
|
|
@ -275,11 +275,9 @@ xbps_write_metadata_pkg_real()
|
||||||
<string>$long_desc</string>
|
<string>$long_desc</string>
|
||||||
_EOF
|
_EOF
|
||||||
#
|
#
|
||||||
# If package sets $openrc_services, add the openrc-service
|
# If package sets $openrc_services, add the OpenRC rundep.
|
||||||
# trigger and OpenRC run dependency.
|
|
||||||
#
|
#
|
||||||
if [ -n "$openrc_services" ]; then
|
if [ -n "$openrc_services" ]; then
|
||||||
triggers="$triggers openrc-service"
|
|
||||||
Add_dependency run OpenRC
|
Add_dependency run OpenRC
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ xbps_write_metadata_scripts_pkg()
|
||||||
local action="$1"
|
local action="$1"
|
||||||
local tmpf=$(mktemp -t xbps-install.XXXXXXXXXX) || exit 1
|
local tmpf=$(mktemp -t xbps-install.XXXXXXXXXX) || exit 1
|
||||||
local fpattern="s|${DESTDIR}||g;s|^\./$||g;/^$/d"
|
local fpattern="s|${DESTDIR}||g;s|^\./$||g;/^$/d"
|
||||||
local targets f info_files
|
local targets f info_files home shell descr groups
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
install) ;;
|
install) ;;
|
||||||
|
@ -97,10 +97,39 @@ _EOF
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Handle system accounts.
|
||||||
|
#
|
||||||
|
if [ -n "${system_accounts}" ]; then
|
||||||
|
_add_trigger system-accounts
|
||||||
|
echo "export system_accounts=\"${system_accounts}\"" >> $tmpf
|
||||||
|
for f in ${system_accounts}; do
|
||||||
|
eval homedir="\$${f}_homedir"
|
||||||
|
eval shell="\$${f}_shell"
|
||||||
|
eval descr="\$${f}_descr"
|
||||||
|
eval groups="\$${f}_groups"
|
||||||
|
if [ -n "$homedir" ]; then
|
||||||
|
echo "export ${f}_homedir=\"$homedir\"" >> $tmpf
|
||||||
|
fi
|
||||||
|
if [ -n "$shell" ]; then
|
||||||
|
echo "export ${f}_shell=\"$shell\"" >> $tmpf
|
||||||
|
fi
|
||||||
|
if [ -n "$descr" ]; then
|
||||||
|
echo "export ${f}_descr=\"$descr\"" >> $tmpf
|
||||||
|
fi
|
||||||
|
if [ -n "$groups" ]; then
|
||||||
|
echo "export ${f}_groups=\"${groups}\"" >> $tmpf
|
||||||
|
fi
|
||||||
|
unset homedir shell descr groups
|
||||||
|
done
|
||||||
|
echo >> $tmpf
|
||||||
|
fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# Handle OpenRC services.
|
# Handle OpenRC services.
|
||||||
#
|
#
|
||||||
if [ -n "${openrc_services}" ]; then
|
if [ -n "${openrc_services}" ]; then
|
||||||
|
_add_trigger openrc-service
|
||||||
echo "export openrc_services=\"${openrc_services}\"" >> $tmpf
|
echo "export openrc_services=\"${openrc_services}\"" >> $tmpf
|
||||||
echo >> $tmpf
|
echo >> $tmpf
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -75,7 +75,8 @@ reset_tmpl_vars()
|
||||||
only_for_archs conf_files keep_libtool_archives \
|
only_for_archs conf_files keep_libtool_archives \
|
||||||
noarch subpackages sourcepkg gtk_iconcache_dirs \
|
noarch subpackages sourcepkg gtk_iconcache_dirs \
|
||||||
abi_depends api_depends triggers openrc_services \
|
abi_depends api_depends triggers openrc_services \
|
||||||
replaces XBPS_EXTRACT_DONE XBPS_CONFIGURE_DONE \
|
replaces system_accounts \
|
||||||
|
XBPS_EXTRACT_DONE XBPS_CONFIGURE_DONE \
|
||||||
XBPS_BUILD_DONE XBPS_INSTALL_DONE FILESDIR DESTDIR \
|
XBPS_BUILD_DONE XBPS_INSTALL_DONE FILESDIR DESTDIR \
|
||||||
SRCPKGDESTDIR PATCHESDIR"
|
SRCPKGDESTDIR PATCHESDIR"
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ include ../vars.mk
|
||||||
TRIGGERS= gtk-icon-cache info-files mimedb register-shell
|
TRIGGERS= gtk-icon-cache info-files mimedb register-shell
|
||||||
TRIGGERS+= xml-catalog gtk-immodules initramfs-tools openrc-service
|
TRIGGERS+= xml-catalog gtk-immodules initramfs-tools openrc-service
|
||||||
TRIGGERS+= update-desktopdb gtk-pixbuf-loaders pango-modules x11-fonts
|
TRIGGERS+= update-desktopdb gtk-pixbuf-loaders pango-modules x11-fonts
|
||||||
|
TRIGGERS+= system-accounts
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all:
|
all:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh -e -e
|
#!/bin/sh -e
|
||||||
#
|
#
|
||||||
# Runs update-initramfs(8) to create/update an initramfs for specified
|
# Runs update-initramfs(8) to create/update an initramfs for specified
|
||||||
# version (if the pkg that is triggering it) or for the currently
|
# version (if the pkg that is triggering it) or for the currently
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh -e -e
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Registers or unregisters OpenRC services into the specified
|
# Registers or unregisters OpenRC services into the specified
|
||||||
# runlevel.
|
# runlevel.
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/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"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$system_accounts" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$TARGET" in
|
||||||
|
post-install)
|
||||||
|
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"
|
||||||
|
|
||||||
|
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" \
|
||||||
|
-s "$shell" -g ${acct} $groups \
|
||||||
|
-r ${acct} && \
|
||||||
|
$passwd_cmd -l ${acct} \
|
||||||
|
2>&1 >/dev/null || exit $?
|
||||||
|
echo "Created ${acct} system user."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
pre-remove)
|
||||||
|
#
|
||||||
|
# Only unregister if we aren't updating a package.
|
||||||
|
#
|
||||||
|
if [ "$UPDATE" = "no" ]; then
|
||||||
|
for acct in ${system_accounts}; do
|
||||||
|
$userdel_cmd ${acct} 2>&1 >/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Removed ${acct} system user/group."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in New Issue