From b7259e3ebb17bd4b9481bafc23c829f3ce761a94 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Sun, 18 Nov 2018 20:12:55 +0100 Subject: [PATCH] Added support to handle the BuiltIn Updater for 3.0.1 packages. --- distribution/debian.sh | 22 ++++++++++++++++++++++ distribution/debian/install | 2 ++ distribution/debian/postinst | 31 +++++++++++++++++++++++++++++++ distribution/debian/postrm | 10 ++++++++++ distribution/debian/preinst | 32 +++++++++++++++++++++++++++++++- 5 files changed, 96 insertions(+), 1 deletion(-) diff --git a/distribution/debian.sh b/distribution/debian.sh index 85fa420ba..eaf536134 100644 --- a/distribution/debian.sh +++ b/distribution/debian.sh @@ -1,7 +1,11 @@ fromdos ./debian/* +cp -r ./debian ./debian_backup BuildVersion=${dependent_build_number:-3.10.0.999} BuildBranch=${dependent_build_branch:-master} +BootstrapVersion=`echo "$BuildVersion" | cut -d. -f1,2,3` +BootstrapUpdater="BuiltIn" +PackageUpdater="apt" echo Version: "$BuildVersion" Branch: "$BuildBranch" @@ -12,10 +16,27 @@ chmod -R ugo-x,ugo+rwX,go-w ./sonarr_bin/* echo Updating changelog for $BuildVersion sed -i "s:{version}:$BuildVersion:g; s:{branch}:$BuildBranch:g;" debian/changelog +sed -i "s:{version}:$BuildVersion:g; s:{updater}:$PackageUpdater:g" debian/preinst debian/postinst debian/postrm +sed -i '/#BEGIN BUILTIN UPDATER/,/#END BUILTIN UPDATER/d' debian/preinst debian/postinst debian/postrm +echo "# Do Not Edit\nReleaseVersion=$BuildVersion\nBranch=$BuildBranch" > release_info +echo "# Do Not Edit\nPackageVersion=$BuildVersion\nReleaseVersion=$BuildVersion\nUpdateMethod=$PackageUpdater\nBranch=$BuildBranch" > package_info echo Running debuild for $BuildVersion debuild -b +# Restore debian directory to the original files +rm -rf ./debian +mv ./debian_backup ./debian + +echo Updating changelog for $BootstrapVersion +sed -i "s:{version}:$BootstrapVersion:g; s:{branch}:$BuildBranch:g;" debian/changelog +sed -i "s:{version}:$BuildVersion:g; s:{updater}:$BootstrapUpdater:g" debian/preinst debian/postinst debian/postrm +sed -i '/#BEGIN BUILTIN UPDATER/d; /#END BUILTIN UPDATER/d' debian/preinst debian/postinst debian/postrm +echo "# Do Not Edit\nPackageVersion=$BootstrapVersion\nReleaseVersion=$BuildVersion\nUpdateMethod=$BootstrapUpdater\nBranch=$BuildBranch" > package_info + +echo Running debuild for $BootstrapVersion +debuild -b + echo Moving stuff around mv ../sonarr_*.deb ./ mv ../sonarr_*.changes ./ @@ -23,6 +44,7 @@ rm ../sonarr_*.build echo Signing Package dpkg-sig -k 884589CE --sign builder "sonarr_${BuildVersion}_all.deb" +dpkg-sig -k 884589CE --sign builder "sonarr_${BootstrapVersion}_all.deb" echo running alien alien -r -v ./*.deb diff --git a/distribution/debian/install b/distribution/debian/install index 5a394e0c9..803796de0 100644 --- a/distribution/debian/install +++ b/distribution/debian/install @@ -1 +1,3 @@ sonarr_bin/* /usr/lib/sonarr/bin +release_info /usr/lib/sonarr/bin +package_info /usr/lib/sonarr diff --git a/distribution/debian/postinst b/distribution/debian/postinst index ac22421f8..c18a7d06d 100644 --- a/distribution/debian/postinst +++ b/distribution/debian/postinst @@ -1,6 +1,8 @@ #!/bin/sh set -e +BUILD_VERSION={version} +UPDATER={updater} . /usr/share/debconf/confmodule db_get sonarr/owning_user @@ -38,12 +40,41 @@ if [ ! -d "$CONFDIR" ]; then 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 \ No newline at end of file diff --git a/distribution/debian/postrm b/distribution/debian/postrm index f1a7facfd..d13374776 100644 --- a/distribution/debian/postrm +++ b/distribution/debian/postrm @@ -1,6 +1,9 @@ #!/bin/sh set -e +BUILD_VERSION={version} +UPDATER={updater} + if [ $1 = "abort-install" ]; then # preinst was aborted, possibly due to NzbDrone still running. # Nothing to do here @@ -12,6 +15,13 @@ if [ $1 = "remove" ] && [ -d /usr/lib/sonarr/bin ]; then rm -rf /usr/lib/sonarr/bin fi +#BEGIN BUILTIN UPDATER +# Remove any existing patch if still present +if [ $1 = "remove" ] && [ -d /usr/lib/sonarr/bin_patch ]; then + rm -rf /usr/lib/sonarr/bin_patch +fi +#END BUILTIN UPDATER + # Purge the entire sonarr configuration directory. # TODO: Maybe move a minimal backup to tmp? if [ $1 = "purge" ] && [ -e /usr/share/debconf/confmodule ]; then diff --git a/distribution/debian/preinst b/distribution/debian/preinst index de128138b..92f38f8a3 100644 --- a/distribution/debian/preinst +++ b/distribution/debian/preinst @@ -1,6 +1,9 @@ #!/bin/sh set -e +BUILD_VERSION={version} +UPDATER={updater} + # Deal with existing nzbdrone installs # # Any existing nzbdrone package would already be in de deconfigured stage, so the binaries are gone. @@ -19,6 +22,33 @@ if [ $1 = "install" ]; then 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 \ No newline at end of file +exit 0