Skip to content

Commit

Permalink
Patch for v3 config migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mreid-tt committed Dec 13, 2022
1 parent 7afe686 commit 0e8c107
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions spk/sonarr/src/service-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ CONFIG_DIR="${SYNOPKG_PKGVAR}/.config"
SONARR_CONFIG_DIR="${CONFIG_DIR}/Sonarr"
PID_FILE="${SONARR_CONFIG_DIR}/sonarr.pid"

LEGACY_SYNOPKG_PKGDEST="${SYNOPKG_PKGDEST}/../nzbdrone"
LEGACY_SYNOPKG_PKGVAR="${SYNOPKG_PKGVAR}/../nzbdrone"
LEGACY_CONFIG_DIR="${LEGACY_SYNOPKG_PKGVAR}/.config"
# Some have it stored in the root of package
LEGACY_CONFIG_DIR="${SYNOPKG_PKGDEST}/.config"
LEGACY_OLD_CONFIG_DIR="${LEGACY_SYNOPKG_PKGDEST}/.config"

# for DSM < 7 only:
GROUP="sc-download"
Expand All @@ -23,14 +26,27 @@ validate_preinst ()
install_log "validate_preinst ${SYNOPKG_PKG_STATUS}"

# check if the installed distribution is a legacy version
if [ -f "${SYNOPKG_PKGDEST}/share/NzbDrone/NzbDrone.exe" ]; then
if [ -f "${LEGACY_SYNOPKG_PKGDEST}/share/NzbDrone/NzbDrone.exe" ]; then
# v2 installed
exit 1
elif [ -f "${LEGACY_SYNOPKG_PKGDEST}/share/Sonarr/Sonarr.exe" ]; then
# v3 installed
exit 1
fi
}

service_postinst ()
{
# if legacy config present, migrate to @appdata folder
mkdir -p "${CONFIG_DIR}" 2>&1
if [ -d "${LEGACY_CONFIG_DIR}/Sonarr" ]; then
echo "Migrate ${LEGACY_CONFIG_DIR}/Sonarr to ${CONFIG_DIR}"
rsync -aX --chown="${SPK_USER}:${SPK_GROUP}" "${LEGACY_CONFIG_DIR}/Sonarr" "${CONFIG_DIR}" 2>&1
elif [ -d "${LEGACY_OLD_CONFIG_DIR}/Sonarr" ]; then
echo "Migrate ${LEGACY_OLD_CONFIG_DIR}/Sonarr to ${CONFIG_DIR}"
rsync -aX --chown="${SPK_USER}:${SPK_GROUP}" "${LEGACY_OLD_CONFIG_DIR}/Sonarr" "${CONFIG_DIR}" 2>&1
fi

echo "Set update required"
# Make Sonarr do an update check on start to avoid possible Sonarr
# downgrade when synocommunity package is updated
Expand All @@ -43,16 +59,6 @@ service_postinst ()

service_preupgrade ()
{
if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -ge 7 ]; then
# ensure config is in @appdata folder
if [ -d "${LEGACY_CONFIG_DIR}" ]; then
if [ "$(realpath "${LEGACY_CONFIG_DIR}")" != "$(realpath "${CONFIG_DIR}")" ]; then
echo "Move ${LEGACY_CONFIG_DIR} to ${CONFIG_DIR}"
mv "${LEGACY_CONFIG_DIR}" "${CONFIG_DIR}" 2>&1
fi
fi
fi

# never update Sonarr distribution, use internal updater only
[ -d "${SYNOPKG_TEMP_UPGRADE_FOLDER}/backup" ] && rm -rf "${SYNOPKG_TEMP_UPGRADE_FOLDER}/backup"
echo "Backup existing distribution to ${SYNOPKG_TEMP_UPGRADE_FOLDER}/backup"
Expand All @@ -72,13 +78,5 @@ service_postupgrade ()

if [ "${SYNOPKG_DSM_VERSION_MAJOR}" -lt 7 ]; then
set_unix_permissions "${SYNOPKG_PKGDEST}/share"
# If backup was created before new-style packages
# new updates/backups will fail due to permissions (see #3185)
if [ -d "/tmp/nzbdrone_backup" ] || [ -d "/tmp/nzbdrone_update" ] || [ -d "/tmp/sonarr_backup" ] || [ -d "/tmp/sonarr_update" ]; then
set_unix_permissions "/tmp/nzbdrone_backup"
set_unix_permissions "/tmp/nzbdrone_update"
set_unix_permissions "/tmp/sonarr_backup"
set_unix_permissions "/tmp/sonarr_update"
fi
fi
}

0 comments on commit 0e8c107

Please sign in to comment.