net-im/tencent-qq: bump version to 3.2.15_p241224
[gentoo-zh.git] / net-im / tencent-qq / files / vercmp.sh
blob5bb467854a6e2164ed14836f4058ba04a9637732
1 #!/usr/bin/env bash
3 # Comparison expressions for semantic versions.
4 # only supports semver standard MAJOR.MINOR.PATCH syntax;
5 # pre-release or build-metadata extensions have undefined behavior.
7 set -o errexit
8 set -o pipefail
10 function usage() {
11 echo "Comparison expressions for semantic versions."
12 echo
13 echo "usage: vercmp VERSION_A OPERATOR VERSION_B"
14 echo
15 echo "OPERATORS"
16 echo
17 echo " lt - Less than"
18 echo " lteq - Less than or equal to"
19 echo " eq - Equal to"
20 echo " gteq - Grater than or equal to"
21 echo " gt - Greater than"
22 echo
25 if [ "$#" -ne 3 ]; then
26 usage
27 exit 1
30 LEFT="$1"
31 OPERATOR="$2"
32 RIGHT="$3"
34 if [ "$LEFT" = "$RIGHT" ]; then
35 COMPARISON=0
36 else
37 SORTED=($(for VER in "$LEFT" "$RIGHT"; do echo "$VER"; done | sort -V))
38 if [ "${SORTED[0]}" = "$LEFT" ]; then
39 COMPARISON=-1
40 else
41 COMPARISON=1
45 OUTCOME=false
47 case $OPERATOR in
48 lt)
49 if [ "$COMPARISON" -eq -1 ]; then
50 OUTCOME=true
54 lteq)
55 if [ "$COMPARISON" -lt 1 ]; then
56 OUTCOME=true
60 eq)
61 if [ "$COMPARISON" -eq 0 ]; then
62 OUTCOME=true
66 gteq)
67 if [ "$COMPARISON" -gt -1 ]; then
68 OUTCOME=true
72 gt)
73 if [ "$COMPARISON" -eq 1 ]; then
74 OUTCOME=true
79 usage
80 exit 1
82 esac
84 VERCMP_QUIET="${VERCMP_QUIET:-false}"
85 if [ ! "$VERCMP_QUIET" = "true" ]; then
86 echo "$OUTCOME"
89 if [ "$OUTCOME" = "true" ]; then
90 exit 0
91 else
92 exit 1