Skip to content
Snippets Groups Projects

switch-branch: prevent downgrades

Merged Josef Schlehofer requested to merge feature/switch-branch-error into master
Viewing commit 60d8994c
Show latest version
2 files
+ 33
1
Preferences
Compare changes
Files
2
  • 60d8994c
    switch-branch: prevent downgrades · 60d8994c
    Karel Koci authored
    Downgrades between versions is dangerous and can break router. It is not
    supported and all fixes and migration scripts are just one way, there is
    no way to revert changes done by them on downgrade. Thus doing downgrade
    can cause pretty much any component to become invalidly configured and
    thus broken.
@@ -108,6 +108,22 @@ fetch_existing_versions() {
LATEST_VERSION="$(echo "$EXISTING_VERSIONS" | head -1)"
}
fetch_target_version() (
. /etc/os-release
case "$OPENWRT_DEVICE_PRODUCT" in
"Turris 1.x")
board="turris1x"
;;
"Turris Omnia")
board="omnia"
;;
"Turris Mox")
board="mox"
;;
esac
curl "https://repo.turris.cz/$1/$board/lists/turris-version"
)
# We allows some branch alternatives. This function replaces them with canonical variant
branch_alts() {
case "$target" in
@@ -338,6 +354,22 @@ if [ "$mode" != "version" ]; then
esac
fi
# Verify that this is not a downgrade
if [ "$force" != "y" ]; then
target_version="$target"
[ "$mode" = "branch" ] \
&& target_version="$(fetch_target_version "$target")"
if [ "$(printf "%s\n%s" "$target_version" "$CUR_VERSION" | sort -V | head -1)" != "$CUR_VERSION" ]; then
cat <<-EOF
$CUR_VERSION -> $target_version
You are attempting to do downgrade while only upgrades are supported.
Downgrade can cause unexpected issues because of migration steps performed on upgrade.
You can use schnapps to rollback to a previous version or perform a factory reset.
EOF
exit 1
fi
fi
###################################
set -x