You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/distribution/debian/postinst

95 lines
3.1 KiB

#!/bin/sh
set -e
BUILD_VERSION={version}
UPDATER={updater}
. /usr/share/debconf/confmodule
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
if [ $1 = "configure" ]; then
# Migrate old Sonarr v3 alpha data dir
if [ -d "/var/opt/sonarr" ] && [ "$CONFDIR" != "/var/opt/sonarr" ] && [ ! -d "$CONFDIR" ]; 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"
chmod -R 775 "$CONFDIR"
fi
# Migrate old NzbDrone data dir
if [ -d "/usr/lib/sonarr/nzbdrone-appdata" ] && [ ! -d "$CONFDIR" ]; then
NZBDRONE_DATA=`readlink /usr/lib/sonarr/nzbdrone-appdata`
if [ -f "$NZBDRONE_DATA/config.xml" ] && [ -f "$NZBDRONE_DATA/nzbdrone.db" ]; then
echo "Found NzbDrone database in $NZBDRONE_DATA, copying to $CONFDIR."
mkdir -p "$CONFDIR"
cp $NZBDRONE_DATA/config.xml $NZBDRONE_DATA/nzbdrone.db* "$CONFDIR/"
chown -R $USER:$GROUP "$CONFDIR"
chmod -R 775 "$CONFDIR"
else
echo "Missing NzbDrone database in $NZBDRONE_DATA, skipping migration."
fi
rm /usr/lib/sonarr/nzbdrone-appdata
fi
fi
# Create data directory
if [ ! -d "$CONFDIR" ]; then
mkdir -p "$CONFDIR"
chown -R $USER:$GROUP "$CONFDIR"
fi
#BEGIN BUILTIN UPDATER
# Apply patch if present
if [ "$UPDATER" = "BuiltIn" ] && [ -f /usr/lib/sonarr/bin_patch/release_info ]; then
# It shouldn't be possible to get a wrong bin_patch, but let's check anyway and throw it away if it's wrong
currentVersion=`cat /usr/lib/sonarr/bin_patch/release_info | grep 'ReleaseVersion=' | cut -d= -f 2`
currentRelease=`echo "$currentVersion" | cut -d. -f1,2,3`
currentBuild=`echo "$currentVersion" | cut -d. -f4`
targetVersion=$BUILD_VERSION
targetRelease=`echo "$targetVersion" | cut -d. -f1,2,3`
targetBuild=`echo "$targetVersion" | cut -d. -f4`
if [ "$currentRelease" = "$targetRelease" ] && [ "$currentBuild" -gt "$targetBuild" ]; then
echo "Applying $currentVersion from BuiltIn updater instead of downgrading to $targetVersion"
rm -rf /usr/lib/sonarr/bin
mv /usr/lib/sonarr/bin_patch /usr/lib/sonarr/bin
else
rm -rf /usr/lib/sonarr/bin_patch
fi
fi
#END BUILTIN UPDATER
# 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" /lib/systemd/system/sonarr.service
#BEGIN BUILTIN UPDATER
if [ $1 = "upgrade" ] && [ "$UPDATER" = "BuiltIn" ]; then
# If we upgraded, signal Sonarr to do an update check on startup instead of scheduled.
touch $CONFDIR/update_required
chown $USER:$GROUP $CONFDIR/update_required
fi
#END BUILTIN UPDATER
#DEBHELPER#
exit 0