Skip to content
Snippets Groups Projects
Verified Commit 32759da4 authored by Karel Koci's avatar Karel Koci :metal: Committed by Josef Schlehofer
Browse files

switch-branch: prevent downgrades

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.
parent 1e8bc818
Branches
Tags
1 merge request!933switch-branch: prevent downgrades
......@@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=switch-branch
PKG_VERSION:=2.6.1
PKG_VERSION:=2.7.0
PKG_RELEASE:=1
PKG_MAINTAINER:=CZ.NIC <packaging@turris.cz>
......
......@@ -108,6 +108,26 @@ 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"
;;
*)
echo "Unknown device model: '$OPENWRT_DEVICE_PRODUCT'" >&2
return 2
;;
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 +358,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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment