|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# check_version.sh |
| 4 | +# |
| 5 | +# -- Verify whether an OpenCoarrays prerequisite meets the required minimum version number. |
| 6 | +# |
| 7 | +# OpenCoarrays is distributed under the OSI-approved BSD 3-clause License: |
| 8 | +# Copyright (c) 2015-2016, Sourcery, Inc. |
| 9 | +# Copyright (c) 2015-2016, Sourcery Institute |
| 10 | +# All rights reserved. |
| 11 | +# |
| 12 | +# Redistribution and use in source and binary forms, with or without modification, |
| 13 | +# are permitted provided that the following conditions are met: |
| 14 | +# |
| 15 | +# 1. Redistributions of source code must retain the above copyright notice, this |
| 16 | +# list of conditions and the following disclaimer. |
| 17 | +# 2. Redistributions in binary form must reproduce the above copyright notice, this |
| 18 | +# list of conditions and the following disclaimer in the documentation and/or |
| 19 | +# other materials provided with the distribution. |
| 20 | +# 3. Neither the names of the copyright holders nor the names of their contributors |
| 21 | +# may be used to endorse or promote products derived from this software without |
| 22 | +# specific prior written permission. |
| 23 | +# |
| 24 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 25 | +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 26 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 27 | +# IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 28 | +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 29 | +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 30 | +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 31 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 32 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 | +# POSSIBILITY OF SUCH DAMAGE. |
| 34 | + |
| 35 | +# Interpret the first argument as the package executable name |
| 36 | +package=$1 |
| 37 | +# Interpret the second argument as the minimimum acceptable package version number |
| 38 | +minimum_version=$2 |
| 39 | +# Interpret the third argument as indicating the desired verbosity |
| 40 | +verbose=$3 |
| 41 | + |
| 42 | +this_script=`basename $0` |
| 43 | + |
| 44 | +usage() |
| 45 | +{ |
| 46 | + echo "" |
| 47 | + echo " $this_script - Bash script for verifyin minimum version numbers for OpenCoarrays prerequisites" |
| 48 | + echo "" |
| 49 | + echo " Usage (optional arguments in square brackets): " |
| 50 | + echo " $this_script [<option>]" |
| 51 | + echo " $this_script <package-name> <minimum-version-number> [--verbose]" |
| 52 | + echo "" |
| 53 | + echo " Options:" |
| 54 | + echo " --help, -h Show this help message" |
| 55 | + echo " --list , -l List the packages whose versions this script can verify" |
| 56 | + echo "" |
| 57 | + echo " Examples:" |
| 58 | + echo "" |
| 59 | + echo " $this_script cmake 3.4.0" |
| 60 | + echo " $this_script flex 2.6.0 --verbose" |
| 61 | + echo " $this_script flex `./build flex --default --query-version`" |
| 62 | + echo " $this_script --help" |
| 63 | + echo " $this_script --list" |
| 64 | + echo "" |
| 65 | + echo "[exit 10]" |
| 66 | + exit 10 |
| 67 | +} |
| 68 | + |
| 69 | +# Print usage information and exit if script is invoked without arguments or with --help or -h as the first argument |
| 70 | +if [ $# == 0 ]; then |
| 71 | + usage | less |
| 72 | + exit 20 |
| 73 | + |
| 74 | +elif [[ $1 == '--help' || $1 == '-h' ]]; then |
| 75 | + usage | less |
| 76 | + exit 30 |
| 77 | + |
| 78 | +elif [[ $1 == '--list' || $1 == '-l' ]]; then |
| 79 | + echo "$this_script currently verifies minimum version numbers for the following OpenCoarrays prerequisites:" |
| 80 | + echo " cmake, flex, bison, m4" |
| 81 | + exit 40 |
| 82 | + |
| 83 | +elif [[ $1 == '-v' || $1 == '-V' || $1 == '--version' ]]; then |
| 84 | + # Print script copyright if invoked with -v, -V, or --version argument |
| 85 | + cmake_project_line=`grep project ../CMakeLists.txt | grep VERSION` |
| 86 | + text_after_version_keyword="${cmake_project_line##*VERSION}" |
| 87 | + text_before_language_keyword="${text_after_version_keyword%%LANGUAGES*}" |
| 88 | + opencoarrays_version=$text_before_language_keyword |
| 89 | + echo "opencoarrays $opencoarrays_version" |
| 90 | + echo "" |
| 91 | + echo "OpenCoarrays prerequisite version verifier" |
| 92 | + echo "Copyright (C) 2015-2016 Sourcery, Inc." |
| 93 | + echo "Copyright (C) 2015-2016 Sourcery Institute" |
| 94 | + echo "" |
| 95 | + echo "OpenCoarrays comes with NO WARRANTY, to the extent permitted by law." |
| 96 | + echo "You may redistribute copies of $this_script under the terms of the" |
| 97 | + echo "BSD 3-Clause License. For more information about these matters, see" |
| 98 | + echo "http://www.sourceryinstitute.org/license.html" |
| 99 | + echo "" |
| 100 | +fi |
| 101 | + |
| 102 | +package_version_header=`$1 --version | head -1` |
| 103 | +if [[ "$verbose" == "--verbose" ]]; then |
| 104 | + echo $package_version_header |
| 105 | +fi |
| 106 | + |
| 107 | +# Extract the text after the final space: |
| 108 | +version=${package_version_header##* } |
| 109 | +major=${version%%.*} |
| 110 | +minor_patch=${version#*.} |
| 111 | +minor=${minor_patch%%.*} |
| 112 | +patch=${version##*.} |
| 113 | +if [[ "$verbose" == "--verbose" ]]; then |
| 114 | + echo "$version = $major . $minor . $patch" |
| 115 | +fi |
| 116 | + |
| 117 | +# Extract the text after the final space: |
| 118 | +min_major=${minimum_version%%.*} |
| 119 | +min_minor_patch=${minimum_version#*.} |
| 120 | +min_minor=${min_minor_patch%%.*} |
| 121 | +min_patch=${minimum_version##*.} |
| 122 | +if [[ "$verbose" == "--verbose" ]]; then |
| 123 | + echo "$minimum_version = $min_major . $min_minor . $min_patch" |
| 124 | +fi |
| 125 | + |
| 126 | +if [ "$(( major < min_major ))" -ne 0 ]; then |
| 127 | + if [[ $verbose == "--verbose" ]]; then |
| 128 | + echo "$major < $min_major" |
| 129 | + fi |
| 130 | + exit 10 |
| 131 | +elif [[ $verbose == "--verbose" ]]; then |
| 132 | + echo "$major >= $min_major" |
| 133 | +fi |
| 134 | + |
| 135 | +if [ "$(( minor < min_minor ))" -ne 0 ]; then |
| 136 | + if [[ $verbose == "--verbose" ]]; then |
| 137 | + echo "$minor < $min_minor" |
| 138 | + fi |
| 139 | + exit 20 |
| 140 | +elif [[ $verbose == "--verbose" ]]; then |
| 141 | + echo "$minor >= $min_minor" |
| 142 | +fi |
| 143 | + |
| 144 | +if [ "$(( patch < min_patch ))" -ne 0 ]; then |
| 145 | + if [[ $verbose == "--verbose" ]]; then |
| 146 | + echo "$patch < $min_patch" |
| 147 | + fi |
| 148 | + exit 30 |
| 149 | +elif [[ $verbose == "--verbose" ]]; then |
| 150 | + echo "$patch >= $min_patch" |
| 151 | +fi |
| 152 | +exit 0 |
0 commit comments