1#!/bin/sh 2# 3# Copyright (C) 2014, The University of Texas at Austin 4# 5# This file is part of libflame and is available under the 3-Clause 6# BSD license, which can be found in the LICENSE file at the top-level 7# directory, or at http://opensource.org/licenses/BSD-3-Clause 8# 9 10# 11# bump-version.sh 12# 13# Field G. Van Zee 14# 15 16 17print_usage() 18{ 19 #local script_name 20 21 # Get the script name 22 #script_name=${0##*/} 23 24 # Echo usage info 25 echo " " 26 echo " "$script_name 27 echo " " 28 echo " Field G. Van Zee" 29 echo " " 30 echo " Performs a series of actions needed when incrementing (bumping) the" 31 echo " libflame version number:" 32 echo " 1. Overwrite the version file with the version string passed" 33 echo " into this script (new_vers)." 34 echo " 2. Commit the updated version file." 35 echo " 3. Create a new tag (named the same as new_vers) which refers to" 36 echo " the commit created in (2)." 37 echo " " 38 echo " Usage:" 39 echo " ${script_name} [options] new_vers" 40 echo " " 41 echo " Arguments:" 42 echo " " 43 echo " new_vers The new version string." 44 echo " " 45 echo " Options:" 46 echo " " 47 echo " -d dry-run" 48 echo " Go through all the motions, but don't actually make any" 49 echo " changes to files or perform any git commits. Note that" 50 echo " this will result in the commits for (2) and (5) above" 51 echo " being equal to the initial commit in the script output." 52 echo " -f VERSFILE version file name" 53 echo " Update VERSFILE with new version string instead of default" 54 echo " 'version' file." 55 56 # Exit with non-zero exit status 57 exit 1 58} 59 60 61main() 62{ 63 # -- BEGIN GLOBAL VARIABLE DECLARATIONS -- 64 65 # The name of the script, stripped of any preceeding path. 66 script_name=${0##*/} 67 68 # The name of the config.mk file. 69 configmk_file='config.mk' 70 71 # The name of the default version file. 72 version_file_def='version' 73 74 # The name of the specified version file. 75 version_file='' 76 77 # Strings used during version query. 78 git_commit_str='' 79 new_version_str='' 80 81 # The script name to use instead of the $0 when outputting messages. 82 output_name='' 83 84 # The git directory. 85 gitdir='.git' 86 87 # Whether we are performing a dry run or not. 88 dry_run_flag="" 89 90 # -- END GLOBAL VARIABLE DECLARATIONS -- 91 92 93 # Process our command line options. 94 while getopts ":dhf:" opt; do 95 case $opt in 96 d ) dry_run_flag="1" ;; 97 f ) version_file=$OPTARG ;; 98 h ) print_usage ;; 99 \? ) print_usage 100 esac 101 done 102 shift $(($OPTIND - 1)) 103 104 105 # If a version file name was not given, set version_file to the default 106 # value. 107 if [ -n "${version_file}" ]; then 108 109 echo "${script_name}: version file specified: '${version_file}'." 110 else 111 112 echo "${script_name}: no version file specified; defaulting to '${version_file_def}'." 113 version_file="${version_file_def}" 114 fi 115 116 117 # Check the number of arguments after command line option processing. 118 if [ $# = "1" ]; then 119 120 new_version_str=$1 121 echo "${script_name}: preparing to bump to version '${new_version_str}'." 122 123 else 124 print_usage 125 fi 126 127 128 # Check if the .git dir exists; if it does not, we do nothing. 129 if [ -d "${gitdir}" ]; then 130 131 echo "${script_name}: found '${gitdir}' directory; assuming git clone." 132 133 git_commit_str=$(git describe --always) 134 echo "${script_name}: initial commit: ${git_commit_str}." 135 136 echo "${script_name}: updating version file '${version_file}'." 137 if [ -z "$dry_run_flag" ]; then 138 echo "${new_version_str}" > ${version_file} 139 fi 140 141 echo "${script_name}: executing: git commit -m \"Version file update (${new_version_str})\" ${version_file}." 142 if [ -z "$dry_run_flag" ]; then 143 git commit -m "Version file update (${new_version_str})" ${version_file} 144 fi 145 146 git_commit_str=$(git describe --always) 147 echo "${script_name}: commit to be tagged: ${git_commit_str}." 148 149 echo "${script_name}: executing: git tag ${new_version_str} ${git_commit_str}." 150 if [ -z "$dry_run_flag" ]; then 151 git tag ${new_version_str} ${git_commit_str} 152 fi 153 154 else 155 156 echo "${script_name}: could not find '${gitdir}' directory; bailing out." 157 158 fi 159 160 161 # Exit peacefully. 162 return 0 163} 164 165 166# The script's main entry point, passing all parameters given. 167main "$@" 168