4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"), version 1.0.
6 # You may only use this file in accordance with the terms of version
9 # A full copy of the text of the CDDL should have accompanied this
10 # source. A copy of the CDDL is also available via the Internet at
11 # http://www.illumos.org/license/CDDL.
15 # Copyright 2022 Marcel Telka
21 [[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1"
22 printf "Usage: perl-version-convert DISTRIBUTION VERSION\n" >&2
23 [[ -n "$1" ]] && exit 1
29 (($# == 1)) && usage
"Missing VERSION to convert"
30 (($# > 2)) && usage
"Too many arguments"
36 function unsupported_version
41 printf "ERROR: Unsupported version format: %s\n" "$VERSION" >&2
42 C
="UNSUPPORTED_VERSION_FORMAT_$VERSION"
45 function convert_version
54 # Handle special cases
58 # (*) The version format for Authen-PAM is 0.XX, but it was integrated
59 # as XX, so we need to follow that.
61 # (*) The actual version format for Crypt-PBKDF2 is 0.YYDDDR (YY -
62 # year, DDD - day in year, R - release in the day) so it had to be
63 # converted to 0.YY.DDD.R to be more accurate, but it was already
64 # integrated as 0.YYDDDR, so we need to follow it for now, because
65 # 0.YY.DDD.R would be considered older than 0.YYDDDR. Possible
66 # conversion of 0.YYDDDR to YY.DDD.R would cause problem in a case the
67 # Crypt-PBKDF2 bump their major version.
69 # (*) Module-Build uses apparently version format 0.XXYY so it had to
70 # be converted to 0.XX.YY, but it was already integrated as 0.XXYY, so
71 # we need to follow it for now.
73 [[ "$DIST" == "Authen-PAM" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 4)) && VERSION=$((1${VERSION:2:2} - 100))
74 [[ "$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}
75 [[ "$DIST" == "Crypt-PBKDF2" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:2:6} - 1000000)) && VERSION=${VERSION:0:1}
76 [[ "$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}
77 [[ "$DIST" == "Email-Sender" && "${VERSION:0:2}" != "0." && "${VERSION:3:2}" == "00" ]] && ((${#VERSION} == 5)) && VER[1]=${VERSION:2:1} && VERSION=${VERSION:0:1}
78 [[ "$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}
79 [[ "$DIST" == "Error" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VERSION=${VERSION:0:4}
80 [[ "$DIST" == "ExtUtils-Depends
" && -n "${VERSION#*.???}" && "${VERSION#*.???}" != "$VERSION" ]] && VER[3]=${VERSION#*.???} && VERSION=${VERSION%${VER[3]}}
81 [[ "$DIST" == "ExtUtils-Depends" && -n "${VERSION#*.?}" ]] && VER[2]=$((1${VERSION#*.?} - 100)) && VERSION=${VERSION%${VERSION#*.?}}
82 [[ "$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}
83 [[ "$DIST" == "IPC-Run
" ]] && ((${#VERSION} == 3)) && VERSION="${VERSION}0"
84 [[ "$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}
85 [[ "$DIST" == "JSON-PP
" ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VERSION=${VERSION:0:4}
86 [[ "$DIST" == "Log-Dispatch
" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 3)) && VERSION=${VERSION}0
87 [[ "$DIST" == "Log-Dispatch" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 5)) && VER[2]=$((1${VERSION:4:1} - 10)) && VERSION=${VERSION:0:4}
88 [[ "$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}
89 [[ "$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}
90 [[ "$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}
91 [[ "$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}
92 [[ "$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}
93 [[ "$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}
94 [[ "$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}
95 [[ "$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}
96 if [[ "$DIST" == "Math-Pari
" && "$VERSION" != "${VERSION/.}" ]] ; then
98 VERSION=${VERSION%.$V}
99 [[ "${V%a}" != "$V" ]] && V="${V%a}0001"
100 [[ "${V%b}" != "$V" ]] && V="${V%b}0002"
101 ((${#V} / 2 * 2 != ${#V})) && V="${V}0"
104 VER
[$i]=$
((1${V:0:2} - 100))
109 [[ "$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}
110 [[ "$DIST" == "Math-BigInt
" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 5)) && VERSION=${VERSION}0
111 [[ "$DIST" == "Math-BigInt" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 8)) && VER[3]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:6}
112 [[ "$DIST" == "MIME-Base32
" ]] && VERSION=${VERSION/%a/.1}
113 [[ "$DIST" == "Module-Build
" ]] && ((${#VERSION} == 6)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VERSION=${VERSION:0:1}
114 [[ "$DIST" == "Mozilla-CA
" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4}
115 [[ "$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}
116 [[ "$DIST" == "Net-IMAP-Simple" ]] && ((${#VERSION} == 7)) && VER[3]=$((1${VERSION:6:1} - 10)) && VERSION=${VERSION:0:6}
117 [[ "$DIST" == "Perl-Critic" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 3)) && VERSION=${VERSION}0
118 [[ "$DIST" == "Perl-Critic
" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 4)) && VERSION=${VERSION}0
119 [[ "$DIST" == "Perl-Tidy" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4}
120 [[ "$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}
121 [[ "$DIST" == "PkgConfig
" && "${VERSION:4:3}" == "026" ]] && ((${#VERSION} == 7)) && VER[1]=$((1${VERSION:2:2} - 100)) && VERSION=${VERSION:0:1}
122 [[ "$DIST" == "Proc-ProcessTable" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 5)) && VER[2]=$((1${VERSION:4:1} - 10)) && VERSION=${VERSION:0:4}
123 [[ "$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}
124 [[ "$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}
125 [[ "$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}
128 VER
[0]=${VERSION%%.*}
130 if [[ "${VER[0]}" != "$VERSION" ]] ; then
133 # Currently we do not support underscore in version
138 ??
) VER
[1]=$
((1$V - 100)) ;;
139 ?.?
) VER
[1]=${V:0:1} && VER
[2]=${V:2:1} ;;
140 ???
) VER
[1]=$
((1$V - 1000)) ;;
141 ?.??
) VER
[1]=${V:0:1} && VER
[2]=$
((1${V:2:2} - 100)) ;;
142 ??.?
) VER
[1]=$
((1${V:0:2} - 100)) && VER
[2]=${V:3:1} ;;
143 ????
) VER
[1]=$
((1${V:0:2} - 100)) && VER
[2]=$
((1${V:2:2} - 100)) ;;
144 ??.??
) VER
[1]=$
((1${V:0:2} - 100)) && VER
[2]=$
((1${V:3:2} - 100)) ;;
145 ???.?
) VER
[1]=$
((1${V:0:3} - 1000)) && VER
[2]=$
((1${V:4:1} - 10)) ;;
146 ?.????
) unsupported_version C
$VERSION ; return ;;
147 ??.???
) unsupported_version C
$VERSION ; return ;;
148 ???.??
) unsupported_version C
$VERSION ; return ;;
149 ????.?
) unsupported_version C
$VERSION ; return ;;
150 ??????
) VER
[1]=$
((1${V:0:3} - 1000)) ; VER
[2]=$
((1${V:3:3} - 1000)) ;;
151 ???.???
)VER
[1]=$
((1${V:0:3} - 1000)) && VER
[2]=$
((1${V:4:3} - 1000)) ;;
152 *) unsupported_version C
$VERSION ; return ;;
157 while ((i
< ${#VER[@]})) ; do
165 # For convenience we replace '::' by '-' in a case somebody calls this script
166 # with module name instead of distribution name.
167 convert_version VER
"${DISTRIBUTION//::/-}" "$VERSION"