Files
Bertrand GounyandClaude Opus 5.5 a762bda77d fix(upgrade): detect downgrades at minor and patch levels
version_lt kept the whole version as a single array element, so the
arithmetic comparison failed and the function always returned false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 22:06:15 +02:00

36 lines
1.0 KiB
Bash

#!/bin/bash
set -euo pipefail
extract_version() {
local version=$1
case "${OPENLDAP_UPGRADE_MIGRATION_LEVEL}" in
patch) echo "${version}" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+' ;;
minor) echo "${version}" | grep -oE '^[0-9]+\.[0-9]+' ;;
major) echo "${version}" | grep -oE '^[0-9]+' ;;
*) container log fatal "Unknown OPENLDAP_UPGRADE_MIGRATION_LEVEL: ${OPENLDAP_UPGRADE_MIGRATION_LEVEL}. Must be patch, minor or major" ;;
esac
}
version_lt() {
local IFS=.
local -a v1 v2
read -ra v1 <<< "$1"
read -ra v2 <<< "$2"
for i in 0 1 2; do
local a=${v1[i]:-0} b=${v2[i]:-0}
(( 10#$a < 10#$b )) && return 0
(( 10#$a > 10#$b )) && return 1
done
return 1
}
write_version() {
container log info "Writing OpenLDAP version ${OPENLDAP_VERSION} to ${OPENLDAP_UPGRADE_CONF_VERSION_FILE} ..."
echo "${OPENLDAP_VERSION}" > "${OPENLDAP_UPGRADE_CONF_VERSION_FILE}"
}
backup_files_prefix() {
echo "${OPENLDAP_UPGRADE_BACKUP_FILES_PREFIX}-${CURRENT_CONF_VERSION_COMPARABLE}"
}