openexr: make architecture independent
[oi-userland.git] / tools / perl-version-convert
blob57500472383c878ec046d8ead5597d7ac5d26c9b
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" == "Error" && "${VERSION:0:2}" == "0." ]] && ((${#VERSION} == 7)) && VER[2]=$((1${VERSION:4:3} - 1000)) && VERSION=${VERSION:0:4}
78 [[ "$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}
79 [[ "$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}
80 [[ "$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}
81 [[ "$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}
82 [[ "$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}
83 [[ "$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}
84 [[ "$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}
85 [[ "$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}
86 [[ "$DIST" == "Module-Build" ]] && ((${#VERSION} == 6)) && VER[1]=$((1${VERSION:2:4} - 10000)) && VERSION=${VERSION:0:1}
87 [[ "$DIST" == "Mozilla-CA" ]] && ((${#VERSION} == 8)) && VER[1]=$((1${VERSION:4:2} - 100)) && VER[2]=$((1${VERSION:6:2} - 100)) && VERSION=${VERSION:0:4}
88 [[ "$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}
89 [[ "$DIST" == "PkgConfig" && "${VERSION:4:3}" == "026" ]] && ((${#VERSION} == 7)) && VER[1]=$((1${VERSION:2:2} - 100)) && VERSION=${VERSION:0:1}
90 [[ "$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}
93 VER[0]=${VERSION%%.*}
95 if [[ "${VER[0]}" != "$VERSION" ]] ; then
96 V=${VERSION#*.}
98 # Currently we do not support underscore in version
99 V=${V//*_*}
101 case "$V" in
102 ?) VER[1]=$V ;;
103 ??) VER[1]=$((1$V - 100)) ;;
104 ?.?) VER[1]=${V:0:1} && VER[2]=${V:2:1} ;;
105 ???) VER[1]=$((1$V - 1000)) ;;
106 ?.??) VER[1]=${V:0:1} && VER[2]=$((1${V:2:2} - 100)) ;;
107 ??.?) VER[1]=$((1${V:0:2} - 100)) && VER[2]=${V:3:1} ;;
108 ????) VER[1]=$((1${V:0:2} - 100)) && VER[2]=$((1${V:2:2} - 100)) ;;
109 ?.????) unsupported_version C $VERSION ; return ;;
110 ??.???) unsupported_version C $VERSION ; return ;;
111 ???.??) unsupported_version C $VERSION ; return ;;
112 ????.?) unsupported_version C $VERSION ; return ;;
113 ??????) VER[1]=$((1${V:0:3} - 1000)) ; VER[2]=$((1${V:3:3} - 1000)) ;;
114 *) unsupported_version C $VERSION ; return ;;
115 esac
119 while ((i < ${#VER[@]})) ; do
120 ((i > 0)) && C="$C."
121 C="$C${VER[$i]}"
122 i=$((i + 1))
123 done
127 # For convenience we replace '::' by '-' in a case somebody calls this script
128 # with module name instead of distribution name.
129 convert_version VER "${DISTRIBUTION//::/-}" "$VERSION"
130 printf "%s\n" "$VER"