File: sysuser-helper

package info (click to toggle)
dh-sysuser 1.3.5.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 72 kB
  • sloc: perl: 56; sh: 30; makefile: 5
file content (44 lines) | stat: -rwxr-xr-x 1,633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
set -eu
exec >/dev/null # only errors should pass.
command="${1}" ; shift

case "${command}" in
    postinst)
        if ! getent passwd "$CONF_USERNAME" ; then
            emptydir=$(mktemp -d) # to inhibit /etc/skel

            set -- --system --shell /usr/sbin/nologin

            # Create a home directory for a system user, unless it is
            # /nonexistent, which must stay nonexistent.
            if [ "${CONF_HOME}" != '/nonexistent' ] ; then
                set -- "$@" --create-home --skel "${emptydir}" --home-dir "${CONF_HOME}"
            fi

            useradd "$@" "${CONF_USERNAME}"
            rmdir "${emptydir}"
        fi
        usermod "${CONF_USERNAME}" -c "Created by dh-sysuser for ${CONF_PACKAGE}"

        # If the user already has another home directory, we use `usermod
        # --move-home'. Unfortunately, a new home is required to be
        # non-existent (and different from previous), so this
        # condition is required.
        if [ ! -d "$CONF_HOME" ] ; then
            usermod --move-home --home "$CONF_HOME" "$CONF_USERNAME"
        fi
        ;;
    prerm)
        # Transition from dh-sysuser=1.3. It did not pass mainainer
        # script arguments to sysuser-helper.
        case ${1:-} in
            purge|abort-install)
                rmdir --ignore-fail-on-non-empty "${CONF_HOME}"
                if ! [ -d "${CONF_HOME}" ] ; then
                    if ! userdel --force "${CONF_USERNAME}" ; then
                        echo >&2 "warning: failed to remove ${CONF_USERNAME}. Proceeding anyway."
                    fi
                fi
        esac
esac