Sonarr/distribution/debian/preinst

92 lines
3.9 KiB
Plaintext
Raw Normal View History

#!/bin/sh
set -e
BUILD_VERSION={version}
UPDATER={updater}
# Deal with existing nzbdrone installs
#
# Existing nzbdrone packages do not have startup scripts and the process might still be running.
# If the user manually installed nzbdrone then the process might still be running too.
if [ $1 = "install" ]; then
psNzbDrone=`ps ax -o'user:20,pid,ppid,unit,args' | grep mono.*NzbDrone\\\\.exe || true`
if [ ! -z "$psNzbDrone" ]; then
# Get the user and optional systemd unit
psNzbDroneUser=`echo "$psNzbDrone" | tr -s ' ' | cut -d ' ' -f 1`
psNzbDroneUnit=`echo "$psNzbDrone" | tr -s ' ' | cut -d ' ' -f 4`
# Get the appdata from the cmdline or get it from the user dir
droneAppData=`echo "$psNzbDrone" | tr ' ' '\n' | grep -- "-data=" | cut -d= -f 2`
if [ "$droneAppData" = "" ]; then
droneUserHome=`getent passwd $psNzbDroneUser | cut -d ':' -f 6`
droneAppData="$droneUserHome/.config/NzbDrone"
fi
if [ "$psNzbDroneUnit" != "-" ] && [ -d /run/systemd/system ]; then
if [ "$psNzbDroneUnit" = "sonarr.service" ]; then
# Conflicts with our new sonarr.service so we have to remove it
echo "NzbDrone systemd startup detected at $psNzbDroneUnit, stopping and removing..."
deb-systemd-invoke stop $psNzbDroneUnit >/dev/null
if [ -f "/etc/systemd/system/$psNzbDroneUnit" ]; then
rm /etc/systemd/system/$psNzbDroneUnit
fi
if [ -f "/usr/lib/systemd/system/$psNzbDroneUnit" ]; then
rm /usr/lib/systemd/system/$psNzbDroneUnit
fi
deb-systemd-helper purge $psNzbDroneUnit >/dev/null
deb-systemd-helper unmask $psNzbDroneUnit >/dev/null
systemctl --system daemon-reload >/dev/null || true
else
# Just disable it, so the user can revisit the settings later
echo "NzbDrone systemd startup detected at $psNzbDroneUnit, stopping and disabling..."
deb-systemd-invoke stop $psNzbDroneUnit >/dev/null
deb-systemd-invoke mask $psNzbDroneUnit >/dev/null
fi
else
# We don't support auto migration for other startup methods, so bail.
# This leaves the sonarr package in an incomplete state.
echo "ps: $psNzbDrone"
echo "Error: An existing Sonarr v2 (NzbDrone) process is running. Remove the NzbDrone auto-startup prior to installing sonarr."
exit 1
fi
# We don't have the debconf configuration yet so we can't migrate the data.
# Instead we symlink so postinst knows where it's at.
if [ -f "/usr/lib/sonarr/nzbdrone-appdata" ]; then
rm "/usr/lib/sonarr/nzbdrone-appdata"
else
mkdir -p "/usr/lib/sonarr"
fi
ln -s $droneAppData /usr/lib/sonarr/nzbdrone-appdata
fi
fi
#BEGIN BUILTIN UPDATER
# Check for supported upgrade paths
if [ $1 = "upgrade" ] && [ "$UPDATER" = "BuiltIn" ] && [ -f /usr/lib/sonarr/bin/release_info ]; then
# If we allow the Built-In updater to upgrade from 3.0.1.123 to 3.0.2.500 and now apt is catching up to 3.0.2.425
# then we need to deal with that 500->425 'downgrade'.
# We do that by preserving the binaries and using those instead for postinst.
currentVersion=`cat /usr/lib/sonarr/bin/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 [ -d /usr/lib/sonarr/bin_patch ]; then
rm -rf /usr/lib/sonarr/bin_patch
fi
# Check if the existing version is already an upgrade for the included build
if [ "$currentRelease" = "$targetRelease" ] && [ "$currentBuild" -gt "$targetBuild" ]; then
echo "Preserving $currentVersion from BuiltIn updater instead of downgrading to $targetVersion"
cp -r /usr/lib/sonarr/bin /usr/lib/sonarr/bin_patch
fi
fi
#END BUILTIN UPDATER
#DEBHELPER#
exit 0