remove glm driver from SPARC distribution, conflicts with driver-sparc-platform.p5m...
[oi-userland.git] / tools / perl-version-convert
blobc805ca225e03b1b90da8bc41e3ce46bb5a77aecd
1 #! /usr/bin/ksh
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
7 # 1.0 of the CDDL.
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
19 function usage
21 [[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1"
22 printf "Usage: perl-version-convert DISTRIBUTION VERSION\n" >&2
23 [[ -n "$1" ]] && exit 1
24 exit 0
28 (($# == 0)) && usage
29 (($# == 1)) && usage "Missing VERSION to convert"
30 (($# > 2)) && usage "Too many arguments"
32 DISTRIBUTION="$1"
33 VERSION="$2"
36 function unsupported_version
38 typeset -n C=$1
39 typeset VERSION=$2
41 printf "ERROR: Unsupported version format: %s\n" "$VERSION" >&2
42 C="UNSUPPORTED_VERSION_FORMAT_$VERSION"
45 function convert_version
47 typeset -n C=$1
48 typeset DIST=$2
49 typeset VERSION=$3
51 typeset -a VER
54 # Handle special cases
56 # Notes:
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" == "Crypt-PBKDF2" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:2:6} - 1000000)) && VERSION=${VERSION:0:1}
75 [[ "$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}
76 [[ "$DIST" == "Email-Sender" && "${VERSION:0:2}" != "0." && "${VERSION:3:2}" == "00" ]] && ((${#VERSION} == 5)) && VER[1]=${VERSION:2:1} && VERSION=${VERSION:0:1}
77 [[ "$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}
78 [[ "$DIST" == "Error" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VERSION=${VERSION:0:4}
79 [[ "$DIST" == "ExtUtils-Depends" && -n "${VERSION#*.???}" && "${VERSION#*.???}" != "$VERSION" ]] && VER[3]=${VERSION#*.???} && VERSION=${VERSION%${VER[3]}}
80 [[ "$DIST" == "ExtUtils-Depends" && -n "${VERSION#*.?}" ]] && VER[2]=$((1${VERSION#*.?} - 100)) && VERSION=${VERSION%${VERSION#*.?}}
81 [[ "$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}
82 [[ "$DIST" == "IPC-Run" ]] && ((${#VERSION} == 3)) && VERSION="${VERSION}0"
83 [[ "$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}
84 [[ "$DIST" == "Log-Dispatch" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 3)) && VERSION=${VERSION}0
85 [[ "$DIST" == "Log-Dispatch" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 5)) && VER[2]=$((1${VERSION:4:1} - 10)) && VERSION=${VERSION:0:4}
86 [[ "$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}
87 [[ "$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}
88 [[ "$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}
89 [[ "$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}
90 [[ "$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}
91 [[ "$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}
92 [[ "$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}
93 [[ "$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}
94 if [[ "$DIST" == "Math-Pari" && "$VERSION" != "${VERSION/.}" ]] ; then
95 V=${VERSION#*.}
96 VERSION=${VERSION%.$V}
97 [[ "${V%a}" != "$V" ]] && V="${V%a}0001"
98 [[ "${V%b}" != "$V" ]] && V="${V%b}0002"
99 ((${#V} / 2 * 2 != ${#V})) && V="${V}0"
101 while ((${#V})) ; do
102 VER[$i]=$((1${V:0:2} - 100))
103 V=${V:2}
104 i=$((i + 1))
105 done
107 [[ "$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}
108 [[ "$DIST" == "MIME-Base32" ]] && VERSION=${VERSION/%a/.1}
109 [[ "$DIST" == "Module-Build" ]] && ((${#VERSION} == 6)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VERSION=${VERSION:0:1}
110 [[ "$DIST" == "Mozilla-CA" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4}
111 [[ "$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}
112 [[ "$DIST" == "Net-IMAP-Simple" ]] && ((${#VERSION} == 7)) && VER[3]=$((1${VERSION:6:1} - 10)) && VERSION=${VERSION:0:6}
113 [[ "$DIST" == "Perl-Critic" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 3)) && VERSION=${VERSION}0
114 [[ "$DIST" == "Perl-Critic" && "${VERSION:0:2}" == "1." ]] && ((${#VERSION} == 4)) && VERSION=${VERSION}0
115 [[ "$DIST" == "Perl-Tidy" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4}
116 [[ "$DIST" == "PkgConfig" && "${VERSION:4:3}" == "026" ]] && ((${#VERSION} == 7)) && VER[1]=$((1${VERSION:2:2} - 100)) && VERSION=${VERSION:0:1}
117 [[ "$DIST" == "Proc-ProcessTable" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 5)) && VER[2]=$((1${VERSION:4:1} - 10)) && VERSION=${VERSION:0:4}
118 [[ "$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}
119 [[ "$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}
120 [[ "$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}
123 VER[0]=${VERSION%%.*}
125 if [[ "${VER[0]}" != "$VERSION" ]] ; then
126 V=${VERSION#*.}
128 # Currently we do not support underscore in version
129 V=${V//*_*}
131 case "$V" in
132 ?) VER[1]=$V ;;
133 ??) VER[1]=$((1$V - 100)) ;;
134 ?.?) VER[1]=${V:0:1} && VER[2]=${V:2:1} ;;
135 ???) VER[1]=$((1$V - 1000)) ;;
136 ?.??) VER[1]=${V:0:1} && VER[2]=$((1${V:2:2} - 100)) ;;
137 ??.?) VER[1]=$((1${V:0:2} - 100)) && VER[2]=${V:3:1} ;;
138 ????) VER[1]=$((1${V:0:2} - 100)) && VER[2]=$((1${V:2:2} - 100)) ;;
139 ??.??) VER[1]=$((1${V:0:2} - 100)) && VER[2]=$((1${V:3:2} - 100)) ;;
140 ???.?) VER[1]=$((1${V:0:3} - 1000)) && VER[2]=$((1${V:4:1} - 10)) ;;
141 ?.????) unsupported_version C $VERSION ; return ;;
142 ??.???) unsupported_version C $VERSION ; return ;;
143 ???.??) unsupported_version C $VERSION ; return ;;
144 ????.?) unsupported_version C $VERSION ; return ;;
145 ??????) VER[1]=$((1${V:0:3} - 1000)) ; VER[2]=$((1${V:3:3} - 1000)) ;;
146 ???.???)VER[1]=$((1${V:0:3} - 1000)) && VER[2]=$((1${V:4:3} - 1000)) ;;
147 *) unsupported_version C $VERSION ; return ;;
148 esac
152 while ((i < ${#VER[@]})) ; do
153 ((i > 0)) && C="$C."
154 C="$C${VER[$i]}"
155 i=$((i + 1))
156 done
160 # For convenience we replace '::' by '-' in a case somebody calls this script
161 # with module name instead of distribution name.
162 convert_version VER "${DISTRIBUTION//::/-}" "$VERSION"
163 printf "%s\n" "$VER"