2018-11-09 19:37:13 +01:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2018-11-18 20:12:55 +01:00
|
|
|
BUILD_VERSION={version}
|
|
|
|
UPDATER={updater}
|
|
|
|
|
2018-11-09 19:37:13 +01:00
|
|
|
# Deal with existing nzbdrone installs
|
|
|
|
#
|
2018-11-18 20:13:24 +01:00
|
|
|
# Existing nzbdrone packages do not have startup scripts and the process might still be running.
|
2018-11-09 19:37:13 +01:00
|
|
|
# If the user manually installed nzbdrone then the process might still be running too.
|
|
|
|
if [ $1 = "install" ]; then
|
2020-10-24 10:41:58 +02:00
|
|
|
psNzbDrone=`ps ax -o'user:20,pid,ppid,unit,args' | grep mono.*NzbDrone\\\\.exe || true`
|
2018-11-18 20:13:24 +01:00
|
|
|
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
|
2019-07-14 21:41:29 +02:00
|
|
|
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
|
2018-11-18 20:13:24 +01:00
|
|
|
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
|
2018-11-09 19:37:13 +01:00
|
|
|
fi
|
|
|
|
|
2018-11-18 20:13:24 +01:00
|
|
|
# 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
|
2018-11-18 20:12:55 +01:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2018-11-09 19:37:13 +01:00
|
|
|
#DEBHELPER#
|
|
|
|
|
2018-11-18 20:12:55 +01:00
|
|
|
exit 0
|