2018-10-27 17:43:41 +00:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2018-11-09 23:51:45 +00:00
|
|
|
# Source debconf library.
|
|
|
|
. /usr/share/debconf/confmodule
|
2018-01-26 19:30:13 +00:00
|
|
|
|
2018-11-09 23:51:45 +00:00
|
|
|
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"
|
2018-01-26 19:30:13 +00:00
|
|
|
|
2018-11-09 23:51:45 +00:00
|
|
|
# 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"
|
2018-01-26 19:30:13 +00:00
|
|
|
fi
|
|
|
|
|
2018-11-10 00:07:41 +00:00
|
|
|
# Migrate old data dir (Sonarr v3 alpha)
|
|
|
|
if [ -d "/var/opt/sonarr" ] && [ "$CONFDIR" != "/var/opt/sonarr" ]; then
|
|
|
|
if [ ! -f "/var/opt/sonarr/sonarr.db" ] && [ -f "/var/opt/sonarr/.config/Sonarr/sonarr.db" ]; then
|
|
|
|
mv "/var/opt/sonarr/.config/Sonarr" "$CONFDIR"
|
|
|
|
rm -rf "/var/opt/sonarr"
|
|
|
|
else
|
|
|
|
mv "/var/opt/sonarr" "$CONFDIR"
|
|
|
|
fi
|
|
|
|
chown -R $USER:$GROUP "$CONFDIR"
|
|
|
|
fi
|
|
|
|
|
2018-11-09 23:51:45 +00:00
|
|
|
# Create data directory
|
|
|
|
if [ ! -d "$CONFDIR" ]; then
|
|
|
|
mkdir -p "$CONFDIR"
|
|
|
|
chown -R $USER:$GROUP "$CONFDIR"
|
2018-01-26 19:30:13 +00:00
|
|
|
fi
|
|
|
|
|
2018-11-10 00:07:41 +00:00
|
|
|
# Set permissions on /usr/lib/sonarr
|
|
|
|
chown -R $USER:$GROUP /usr/lib/sonarr
|
2018-11-09 23:51:45 +00:00
|
|
|
|
|
|
|
# Update sonarr.service file
|
2018-11-10 00:07:41 +00:00
|
|
|
sed -i "s:User=sonarr:User=$USER:g; s:Group=sonarr:Group=$GROUP:g; s:-data=/var/lib/sonarr:-data=$CONFDIR:g" $SYSTEMD_UNIT
|
2018-11-09 23:51:45 +00:00
|
|
|
|
|
|
|
#DEBHELPER#
|
2018-01-26 19:30:13 +00:00
|
|
|
|
2018-11-09 23:51:45 +00:00
|
|
|
exit 0
|