#! /usr/bin/ksh # # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2022 Marcel Telka # function usage { [[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1" printf "Usage: perl-version-convert DISTRIBUTION VERSION\n" >&2 [[ -n "$1" ]] && exit 1 exit 0 } (($# == 0)) && usage (($# == 1)) && usage "Missing VERSION to convert" (($# > 2)) && usage "Too many arguments" DISTRIBUTION="$1" VERSION="$2" function unsupported_version { typeset -n C=$1 typeset VERSION=$2 printf "ERROR: Unsupported version format: %s\n" "$VERSION" >&2 C="UNSUPPORTED_VERSION_FORMAT_$VERSION" } function convert_version { typeset -n C=$1 typeset DIST=$2 typeset VERSION=$3 typeset -a VER # # Handle special cases # # Notes: # # (*) The version format for Authen-PAM is 0.XX, but it was integrated # as XX, so we need to follow that. # # (*) The actual version format for Crypt-PBKDF2 is 0.YYDDDR (YY - # year, DDD - day in year, R - release in the day) so it had to be # converted to 0.YY.DDD.R to be more accurate, but it was already # integrated as 0.YYDDDR, so we need to follow it for now, because # 0.YY.DDD.R would be considered older than 0.YYDDDR. Possible # conversion of 0.YYDDDR to YY.DDD.R would cause problem in a case the # Crypt-PBKDF2 bump their major version. # # (*) Module-Build uses apparently version format 0.XXYY so it had to # be converted to 0.XX.YY, but it was already integrated as 0.XXYY, so # we need to follow it for now. # [[ "$DIST" == "Authen-PAM" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 4)) && VERSION=$((1${VERSION:2:2} - 100)) [[ "$DIST" == "CPAN-Meta" && "${VERSION:0:2}" == "2." ]] && ((${#VERSION} == 8)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VER[3]=$((1${VERSION:7:1} - 10)) && VERSION=${VERSION:0:4} [[ "$DIST" == "Crypt-PBKDF2" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:2:6} - 1000000)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Email-Sender" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 8)) && VER[1]=${VERSION:2:1} && VER[2]=$((1${VERSION:3:5} - 100000)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Email-Sender" && "${VERSION:0:2}" != "0." && "${VERSION:3:2}" == "00" ]] && ((${#VERSION} == 5)) && VER[1]=${VERSION:2:1} && VERSION=${VERSION:0:1} [[ "$DIST" == "Email-Sender" && "${VERSION:0:2}" != "0." ]] && ((${#VERSION} == 5)) && VER[1]=${VERSION:2:1} && VER[2]=$((1${VERSION:3:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Error" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VERSION=${VERSION:0:4} [[ "$DIST" == "ExtUtils-Depends" && -n "${VERSION#*.???}" && "${VERSION#*.???}" != "$VERSION" ]] && VER[3]=${VERSION#*.???} && VERSION=${VERSION%${VER[3]}} [[ "$DIST" == "ExtUtils-Depends" && -n "${VERSION#*.?}" ]] && VER[2]=$((1${VERSION#*.?} - 100)) && VERSION=${VERSION%${VERSION#*.?}} [[ "$DIST" == "Geography-Countries" ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:4} [[ "$DIST" == "IPC-Run" ]] && ((${#VERSION} == 3)) && VERSION="${VERSION}0" [[ "$DIST" == "IPC-Run" ]] && ((${#VERSION} == 10)) && VER[3]=$((1${VERSION:9:1} - 10)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[1]=$((1${VERSION:4:2} - 100)) && VERSION=${VERSION:0:4} [[ "$DIST" == "JSON-PP" ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VERSION=${VERSION:0:4} [[ "$DIST" == "Log-Dispatch" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 3)) && VERSION=${VERSION}0 [[ "$DIST" == "Log-Dispatch" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 5)) && VER[2]=$((1${VERSION:4:1} - 10)) && VERSION=${VERSION:0:4} [[ "$DIST" == "Mail-AuthenticationResults" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-AuthenticationResults" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 12)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VER[4]=${VERSION:11:1} && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-AuthenticationResults" && "${VERSION:0:2}" == "2." ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-AuthenticationResults" && "${VERSION:0:2}" == "2." ]] && ((${#VERSION} == 12)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VER[4]=${VERSION:11:1} && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-DKIM" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-DKIM" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 12)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VER[4]=${VERSION:11:1} && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-DMARC" && "${VERSION:1:1}" == "." ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Mail-DMARC" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:2:2} - 100)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VER[3]=$((1${VERSION:7:1} - 10)) && VERSION=${VERSION:0:1} if [[ "$DIST" == "Math-Pari" && "$VERSION" != "${VERSION/.}" ]] ; then V=${VERSION#*.} VERSION=${VERSION%.$V} [[ "${V%a}" != "$V" ]] && V="${V%a}0001" [[ "${V%b}" != "$V" ]] && V="${V%b}0002" ((${#V} / 2 * 2 != ${#V})) && V="${V}0" i=1 while ((${#V})) ; do VER[$i]=$((1${V:0:2} - 100)) V=${V:2} i=$((i + 1)) done fi [[ "$DIST" == "Mail-SPF" && "${VERSION:0:2}" == "3." ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Math-BigInt" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 5)) && VERSION=${VERSION}0 [[ "$DIST" == "Math-BigInt" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 8)) && VER[3]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:6} [[ "$DIST" == "MIME-Base32" ]] && VERSION=${VERSION/%a/.1} [[ "$DIST" == "Module-Build" ]] && ((${#VERSION} == 6)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Mozilla-CA" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4} [[ "$DIST" == "Net-DNS-Resolver-Mock" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Net-IMAP-Simple" ]] && ((${#VERSION} == 7)) && VER[3]=$((1${VERSION:6:1} - 10)) && VERSION=${VERSION:0:6} [[ "$DIST" == "Perl-Critic" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 3)) && VERSION=${VERSION}0 [[ "$DIST" == "Perl-Critic" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 4)) && VERSION=${VERSION}0 [[ "$DIST" == "Perl-Tidy" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4} [[ "$DIST" == "perlfaq" && "${VERSION:0:4}" == "5.20" ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "PkgConfig" && "${VERSION:4:3}" == "026" ]] && ((${#VERSION} == 7)) && VER[1]=$((1${VERSION:2:2} - 100)) && VERSION=${VERSION:0:1} [[ "$DIST" == "Proc-ProcessTable" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 5)) && VER[2]=$((1${VERSION:4:1} - 10)) && VERSION=${VERSION:0:4} [[ "$DIST" == "Regexp-Common" ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:4} [[ "$DIST" == "Test-Regexp" ]] && ((${#VERSION} == 10)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VER[3]=$((1${VERSION:8:2} - 100)) && VERSION=${VERSION:0:4} [[ "$DIST" == "YAML-LibYAML" && "${VERSION:0:4}" == "0.90" && "${VERSION:5:1}" == "." ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:1} - 10)) && VER[3]=$((1${VERSION:6:1} - 10)) && VERSION=${VERSION:0:4} C= VER[0]=${VERSION%%.*} if [[ "${VER[0]}" != "$VERSION" ]] ; then V=${VERSION#*.} # Currently we do not support underscore in version V=${V//*_*} case "$V" in ?) VER[1]=$V ;; ??) VER[1]=$((1$V - 100)) ;; ?.?) VER[1]=${V:0:1} && VER[2]=${V:2:1} ;; ???) VER[1]=$((1$V - 1000)) ;; ?.??) VER[1]=${V:0:1} && VER[2]=$((1${V:2:2} - 100)) ;; ??.?) VER[1]=$((1${V:0:2} - 100)) && VER[2]=${V:3:1} ;; ????) VER[1]=$((1${V:0:2} - 100)) && VER[2]=$((1${V:2:2} - 100)) ;; ??.??) VER[1]=$((1${V:0:2} - 100)) && VER[2]=$((1${V:3:2} - 100)) ;; ???.?) VER[1]=$((1${V:0:3} - 1000)) && VER[2]=$((1${V:4:1} - 10)) ;; ?.????) unsupported_version C $VERSION ; return ;; ??.???) unsupported_version C $VERSION ; return ;; ???.??) unsupported_version C $VERSION ; return ;; ????.?) unsupported_version C $VERSION ; return ;; ??????) VER[1]=$((1${V:0:3} - 1000)) ; VER[2]=$((1${V:3:3} - 1000)) ;; ???.???)VER[1]=$((1${V:0:3} - 1000)) && VER[2]=$((1${V:4:3} - 1000)) ;; *) unsupported_version C $VERSION ; return ;; esac fi i=0 while ((i < ${#VER[@]})) ; do ((i > 0)) && C="$C." C="$C${VER[$i]}" i=$((i + 1)) done } # For convenience we replace '::' by '-' in a case somebody calls this script # with module name instead of distribution name. convert_version VER "${DISTRIBUTION//::/-}" "$VERSION" printf "%s\n" "$VER"