diff --git a/user/local/share/towel/bin/towel-update b/user/local/share/towel/bin/towel-update index ae5d0ae..7a7bcf4 100755 --- a/user/local/share/towel/bin/towel-update +++ b/user/local/share/towel/bin/towel-update @@ -168,7 +168,16 @@ if [ "$assume_yes" != "true" ]; then fi tmpdir="$(/usr/bin/mktemp -d)" -trap '/usr/bin/rm -rf "$tmpdir"' EXIT +restore_backup="" + +function _towel_update_cleanup() { + if [ -n "$restore_backup" ]; then + rm -rf "$TOWEL_DATA" + mv "$backup_current" "$TOWEL_DATA" 2>/dev/null + fi + /usr/bin/rm -rf "$tmpdir" +} +trap _towel_update_cleanup EXIT base_url="https://github.com/${TOWEL_GITHUB_REPO}/releases/download/v${latest_version}" tarball="towel-${latest_version}.tar.gz" @@ -214,7 +223,7 @@ source "$src/user/local/share/towel/bin/towel-common" backup_current="${TOWEL_DATA}.backup.$(date +%s)" mv "$TOWEL_DATA" "$backup_current" 2>/dev/null || true -trap 'rm -rf "$TOWEL_DATA"; mv "$backup_current" "$TOWEL_DATA" 2>/dev/null' EXIT +restore_backup="1" towel_install_from_dir "$src" || { echo 1>&2 "towel update --apply failed: installation error" @@ -222,7 +231,7 @@ towel_install_from_dir "$src" || { } rm -rf "$backup_current" -trap - EXIT +restore_backup="" echo "towel updated to $latest_version." echo "Note: distrobox/containers configs were not refreshed." echo " Re-run ./install from the tarball to update those."