Skip to content

Commit 8fa5414

Browse files
authored
fix: Towel scripts got reloaded when update changes them. (#10)
mv current version before installing new version
1 parent b065b48 commit 8fa5414

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

user/local/share/towel/bin/towel-update

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,23 @@ if [ ! -d "$src/user/local/share/towel" ]; then
206206
exit 1
207207
fi
208208

209+
set -e
209210
# Source towel-common from the new tarball so towel_install_from_dir reflects
210211
# any changes in the release being installed.
211212
# shellcheck source=/dev/null
212213
source "$src/user/local/share/towel/bin/towel-common"
213214

214-
towel_install_from_dir "$src"
215+
backup_current="${TOWEL_DATA}.backup.$(date +%s)"
216+
mv "$TOWEL_DATA" "$backup_current" 2>/dev/null || true
217+
trap 'rm -rf "$TOWEL_DATA"; mv "$backup_current" "$TOWEL_DATA" 2>/dev/null' EXIT
215218

219+
towel_install_from_dir "$src" || {
220+
echo 1>&2 "towel update --apply failed: installation error"
221+
exit 1
222+
}
223+
224+
rm -rf "$backup_current"
225+
trap - EXIT
216226
echo "towel updated to $latest_version."
217227
echo "Note: distrobox/containers configs were not refreshed."
218228
echo " Re-run ./install from the tarball to update those."

0 commit comments

Comments
 (0)