2018-10-27 19:43:41 +02:00
|
|
|
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
|
2018-11-18 20:12:55 +01:00
|
|
|
BUILD_VERSION={version}
|
|
|
|
UPDATER={updater}
|
2018-01-26 20:30:13 +01:00
|
|
|
|
2018-11-18 20:11:04 +01:00
|
|
|
. /usr/share/debconf/confmodule
|
2018-11-10 00:51:45 +01:00
|
|
|
db_get sonarr/owning_user
|
|
|
|
USER="$RET"
|
|
|
|
db_get sonarr/owning_group
|
|
|
|
GROUP="$RET"
|
|
|
|
db_get sonarr/config_directory
|
|
|
|
CONFDIR="$RET"
|
2018-01-26 20:30:13 +01:00
|
|
|
|
2018-11-10 00:51:45 +01: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 20:30:13 +01:00
|
|
|
fi
|
|
|
|
|
2018-11-18 20:11:04 +01:00
|
|
|
if [ $1 = "configure" ]; then
|
2018-12-30 15:27:41 +01:00
|
|
|
# Migrate old Sonarr v3 alpha data dir from /var/opt/sonarr or user home
|
2018-11-18 20:11:04 +01:00
|
|
|
if [ -d "/var/opt/sonarr" ] && [ "$CONFDIR" != "/var/opt/sonarr" ] && [ ! -d "$CONFDIR" ]; then
|
2018-12-30 15:27:41 +01:00
|
|
|
varoptRoot="/var/opt/sonarr"
|
|
|
|
varoptAppData="$varoptRoot/.config/Sonarr"
|
|
|
|
sonarrUserHome=`getent passwd $USER | cut -d ':' -f 6`
|
|
|
|
sonarrAppData="$sonarrUserHome/.config/Sonarr"
|
2019-01-02 22:06:58 +01:00
|
|
|
if [ -f "$varoptRoot/sonarr.db" ]; then
|
2018-12-30 15:27:41 +01:00
|
|
|
# Handle /var/opt/sonarr/sonarr.db
|
|
|
|
mv "$varoptRoot" "$CONFDIR"
|
|
|
|
elif [ -f "$varoptAppData/sonarr.db" ]; then
|
|
|
|
# Handle /var/opt/sonarr/.config/Sonarr/sonarr.db
|
|
|
|
mv "$varoptAppData" "$CONFDIR"
|
|
|
|
rm -rf "$varoptRoot"
|
|
|
|
elif [ -f "$sonarrAppData/sonarr.db" ]; then
|
|
|
|
# Handle ~/.config/Sonarr/sonarr.db
|
|
|
|
mv "$sonarrAppData" "$CONFDIR"
|
|
|
|
rm -rf "$sonarrAppData"
|
2018-11-18 20:11:04 +01:00
|
|
|
else
|
2018-12-30 15:27:41 +01:00
|
|
|
mv "$varoptRoot" "$CONFDIR"
|
2018-11-18 20:11:04 +01:00
|
|
|
fi
|
|
|
|
chown -R $USER:$GROUP "$CONFDIR"
|
|
|
|
chmod -R 775 "$CONFDIR"
|
2018-11-10 01:07:41 +01:00
|
|
|
fi
|
2018-11-18 20:13:24 +01:00
|
|
|
|
|
|
|
# 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
|
2018-11-10 01:07:41 +01:00
|
|
|
fi
|
|
|
|
|
2018-11-10 00:51:45 +01:00
|
|
|
# Create data directory
|
|
|
|
if [ ! -d "$CONFDIR" ]; then
|
|
|
|
mkdir -p "$CONFDIR"
|
|
|
|
chown -R $USER:$GROUP "$CONFDIR"
|
2018-01-26 20:30:13 +01:00
|
|
|
fi
|
|
|
|
|
2018-11-18 20:12:55 +01:00
|
|
|
#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
|
|
|
|
|
2018-11-10 01:07:41 +01:00
|
|
|
# Set permissions on /usr/lib/sonarr
|
|
|
|
chown -R $USER:$GROUP /usr/lib/sonarr
|
2018-11-10 00:51:45 +01:00
|
|
|
|
|
|
|
# Update sonarr.service file
|
2018-11-18 20:11:04 +01:00
|
|
|
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
|
2018-11-10 00:51:45 +01:00
|
|
|
|
2018-11-18 20:12:55 +01:00
|
|
|
#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
|
|
|
|
|
2018-11-10 00:51:45 +01:00
|
|
|
#DEBHELPER#
|
2018-01-26 20:30:13 +01:00
|
|
|
|
2019-07-14 21:35:16 +02:00
|
|
|
exit 0
|