1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-12 11:15:43 +02:00
Sonarr/distribution/debian/postinst

48 lines
1.2 KiB
Bash

#!/bin/sh
set -e
# Source debconf library.
. /usr/share/debconf/confmodule
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"
# 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
# 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
# Create data directory
if [ ! -d "$CONFDIR" ]; then
mkdir -p "$CONFDIR"
chown -R $USER:$GROUP "$CONFDIR"
fi
# Set permissions on /usr/lib/sonarr
chown -R $USER:$GROUP /usr/lib/sonarr
# Update sonarr.service file
sed -i "s:User=sonarr:User=$USER:g; s:Group=sonarr:Group=$GROUP:g; s:-data=/var/lib/sonarr:-data=$CONFDIR:g" $SYSTEMD_UNIT
#DEBHELPER#
exit 0