From 40a7cf32c545e0610183097c7a1c5316052e8c7b Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sat, 10 Nov 2018 00:51:45 +0100 Subject: [PATCH] Added debconf to allow user to set user, group and config dir. Only the group is high prio and thus asked for by default. --- distribution/debian.sh | 1 + distribution/debian/config | 12 +++++++++ distribution/debian/control | 4 +-- distribution/debian/postinst | 40 +++++++++++++++++++----------- distribution/debian/sonarr.service | 3 ++- distribution/debian/templates | 19 ++++++++++++++ 6 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 distribution/debian/config create mode 100644 distribution/debian/templates diff --git a/distribution/debian.sh b/distribution/debian.sh index 0d14ec424..6ac107666 100644 --- a/distribution/debian.sh +++ b/distribution/debian.sh @@ -2,6 +2,7 @@ fromdos ./debian/* echo Version: "$dependent_build_number" Branch: "$dependent_build_branch" rm -r ./sonarr_bin/Sonarr.Update +chmod -R 664 ./sonarr_bin/* echo Updating changelog sed -i "s/{version}/$dependent_build_number/g" debian/changelog diff --git a/distribution/debian/config b/distribution/debian/config new file mode 100644 index 000000000..28d9b5bce --- /dev/null +++ b/distribution/debian/config @@ -0,0 +1,12 @@ +#!/bin/sh -e + +. /usr/share/debconf/confmodule + +db_beginblock +db_input medium sonarr/owning_user || true +db_input high sonarr/owning_group || true +db_input low sonarr/config_directory || true +db_endblock +db_go + +exit 0 \ No newline at end of file diff --git a/distribution/debian/control b/distribution/debian/control index f5fde9017..f62a824eb 100644 --- a/distribution/debian/control +++ b/distribution/debian/control @@ -9,14 +9,14 @@ Build-Depends: debhelper (>= 9), dh-systemd (>= 1.5), mono-devel (>= 4.6), libmono-cil-dev (>= 4.6), - cli-common-dev (>= 0.9) + cli-common-dev (>= 0.5.7) Package: sonarr Architecture: all Provides: nzbdrone Conflicts: nzbdrone Replaces: nzbdrone -Depends: libsqlite3-0 (>= 3.7), libmediainfo0v5 (>= 0.7.52), ${shlibs:Depends}, ${cli:Depends}, ${misc:Depends} +Depends: adduser, libsqlite3-0 (>= 3.7), libmediainfo0v5 (>= 0.7.52), mono-runtime (>= 5.4), ${shlibs:Depends}, ${cli:Depends}, ${misc:Depends} Recommends: sqlite3 (>= 3.7), mediainfo (>= 0.7.52), ${shlibs:Recommends}, ${cli:Recommends}, ${misc:Recommends} Suggests: ${shlibs:Suggests}, ${cli:Suggests}, ${misc:Suggests} Description: Internet PVR diff --git a/distribution/debian/postinst b/distribution/debian/postinst index 6716dc239..e2729e59b 100644 --- a/distribution/debian/postinst +++ b/distribution/debian/postinst @@ -1,25 +1,37 @@ #!/bin/sh set -e -USER="sonarr" +# Source debconf library. +. /usr/share/debconf/confmodule -# Add User -if ! getent passwd "$USER" >/dev/null; then - adduser --quiet --system --shell /bin/bash --home /var/opt/sonarr --group "$USER" +SYSTEMD_UNIT=/lib/systemd/system/sonarr.service +db_get sonarr/owning_user +USER="$RET" +db_get sonarr/owning_group +GROUP="$RET" +db_get sonarr/config_directory +CONFDIR="$RET" - if ! getent group "$USER" >/dev/null; then - groupadd "$USER" - usermod -a -G "$USER" "$USER" - fi +# Add User and Group +if ! getent group "$GROUP" >/dev/null; then + groupadd "$GROUP" +fi +if ! getent passwd "$USER" >/dev/null; then + adduser --system --no-create-home --ingroup "$GROUP" "$USER" fi -# Create home directory -if [ ! -d /var/opt/sonarr ]; then - mkdir -p /var/opt/sonarr - chown -R $USER: /var/opt/sonarr +# Create data directory +if [ ! -d "$CONFDIR" ]; then + mkdir -p "$CONFDIR" + chown -R $USER:$GROUP "$CONFDIR" fi # Set permissions on /opt/sonarr -chown -R $USER: /opt/sonarr +chown -R $USER:$GROUP /opt/sonarr + +# Update sonarr.service file +sed -i "s:User=sonarr:User=$USER:g; s:Group=sonarr:Group=$GROUP:g; s:-data=/var/opt/sonarr:-data=$CONFDIR:g" $SYSTEMD_UNIT + +#DEBHELPER# -#DEBHELPER# \ No newline at end of file +exit 0 \ No newline at end of file diff --git a/distribution/debian/sonarr.service b/distribution/debian/sonarr.service index d1a8c9264..ae035ef6d 100644 --- a/distribution/debian/sonarr.service +++ b/distribution/debian/sonarr.service @@ -5,9 +5,10 @@ After=network.target [Service] User=sonarr Group=sonarr +UMask=002 Type=simple -ExecStart=/usr/bin/mono --debug /opt/sonarr/bin/Sonarr.exe -nobrowser +ExecStart=/usr/bin/mono --debug /opt/sonarr/bin/Sonarr.exe -nobrowser -data=/var/opt/sonarr TimeoutStopSec=20 KillMode=process Restart=on-failure diff --git a/distribution/debian/templates b/distribution/debian/templates new file mode 100644 index 000000000..ef340af33 --- /dev/null +++ b/distribution/debian/templates @@ -0,0 +1,19 @@ +Template: sonarr/owning_user +Type: string +Default: sonarr +Description: Sonarr user: + Specify the user that Sonarr must run as. The user will be created if it does not already exist. + +Template: sonarr/owning_group +Type: string +Default: sonarr +Description: Sonarr group: + Specify the group that Sonarr must run as. The group will be created if it does not already exist. + If the user doesn't already exist then this group will be specified as the user's primary group. + Any media files created by Sonarr will be writeable by this group. + +Template: sonarr/config_directory +Type: string +Default: /var/lib/sonarr +Description: Config directory: + Specify the directory where Sonarr stores the internal database and metadata. Media content will be stored elsewhere.