Skip to content

Commit 5b0543d

Browse files
committed
Fix engine version comparison to prevent false downgrade prompts (#28)
Running a newer engine than pinned now shows "up to date" instead of suggesting a downgrade. Uses semver comparison (major.minor.patch).
1 parent cbf438e commit 5b0543d

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

mtproxymax.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ escape_md() {
405405
echo "$text"
406406
}
407407

408+
# Compare version strings: returns 0 if v1 >= v2 (semver part only, ignores commit hash)
409+
_version_gte() {
410+
local v1="${1%%-*}" v2="${2%%-*}" # strip commit hash
411+
local IFS='.'; local a=($v1) b=($v2)
412+
local i
413+
for i in 0 1 2; do
414+
local n1=${a[$i]:-0} n2=${b[$i]:-0}
415+
(( n1 > n2 )) && return 0
416+
(( n1 < n2 )) && return 1
417+
done
418+
return 0
419+
}
420+
408421
# Get public IP address
409422
_PUBLIC_IP_CACHE=""
410423
_PUBLIC_IP_CACHE_AGE=0
@@ -3003,15 +3016,17 @@ self_update() {
30033016
local _expected_ver="${TELEMT_MIN_VERSION}-${TELEMT_COMMIT}"
30043017
local _current_ver
30053018
_current_ver=$(get_telemt_version)
3006-
if [ "$_current_ver" != "$_expected_ver" ]; then
3019+
if [ "$_current_ver" = "$_expected_ver" ]; then
3020+
log_success "Telemt engine is up to date (v${_current_ver})"
3021+
elif _version_gte "$_current_ver" "$_expected_ver"; then
3022+
log_success "Telemt engine is up to date (v${_current_ver})"
3023+
else
30073024
log_info "Engine update: v${_current_ver} -> v${_expected_ver}"
30083025
build_telemt_image true
30093026
if is_proxy_running; then
30103027
load_secrets
30113028
restart_proxy_container
30123029
fi
3013-
else
3014-
log_success "Telemt engine is up to date (v${_current_ver})"
30153030
fi
30163031
}
30173032

@@ -4871,6 +4886,8 @@ cli_main() {
48714886
local _current; _current=$(get_telemt_version)
48724887
if [ "$_current" = "$_expected" ]; then
48734888
log_success "Engine is up to date"
4889+
elif _version_gte "$_current" "$_expected"; then
4890+
log_success "Engine is up to date (v${_current}, ahead of pinned v${_expected})"
48744891
else
48754892
log_info "Update available: v${_current} -> v${_expected}"
48764893
echo -e " ${DIM}Run: mtproxymax update${NC}"
@@ -5555,6 +5572,8 @@ show_engine_menu() {
55555572
local _current; _current=$(get_telemt_version)
55565573
if [ "$_current" = "$_expected" ]; then
55575574
echo -e " ${GREEN}${SYM_OK} Engine is up to date${NC}"
5575+
elif _version_gte "$_current" "$_expected"; then
5576+
echo -e " ${GREEN}${SYM_OK} Engine is up to date (ahead of pinned)${NC}"
55585577
else
55595578
echo -e " ${YELLOW}Update available: v${_current} -> v${_expected}${NC}"
55605579
echo -e " ${DIM}Run: mtproxymax update${NC}"

0 commit comments

Comments
 (0)