Skip to content

Instantly share code, notes, and snippets.

@rbf
Last active December 22, 2015 06:49
Show Gist options
  • Save rbf/6434162 to your computer and use it in GitHub Desktop.
Save rbf/6434162 to your computer and use it in GitHub Desktop.
Shell tool to help creating a meaningful git tag.

%gh-tag % https://gist.github.com/rbf/6434162

Description

gh-tag is a shell tool to help creating a meaningful tag in the git repo in the current folder. It will show a pre-filled tag message, with a out-commented list of the commits that have been done since the last released version (i.e. annotated tag). If GitHub issues are mentioned in the commit messages, the issues titles will be also pre–filled in the tag message.

Installation

To install this tool directly to your /usr/local/bin you can use following command:

bash <(curl -sSL https://gist.github.com/rbf/6434162/raw/install)

Usage

The main usage is simply to type gh-tag without options and arguments in the root folder of a git repository. You will be prompted for the new tag version (enforcing the vX.X format) with a meaningful suggestion. Leave the field blank and press enter to use the suggested version tag.

Once you have specified the name of the new tag, gh-tag will parse the commit messages since the last version (i.e. the last annotated tag) or since the first commit, if no annotated tag is found.

If mentions to GitHub issues are found in some of the commit messages, gh-tag will try to retrieve the title of those issues to provide a meaningful template for the tag message. In order to be able to query GitHub, you might be requested to enter a valid GitHub access token. You will be able to ask gh-tag to create one for you, if needed.

After that, a text editor will open with a meaningful template for the tag message. You might want to modify the tag message at that point. Lines starting with # will be ignored, but an empty message will not abort the creation of the tag.

Options

Use gh-tag --commits (or gh-tag -c) to only print the log for the commits that have been done since the last annotated tag. This might be useful to check what has been done since the last release.

Use gh-tag --tag-message (or gh-tag -n) to only print the text that would be used for the tag message. This might be useful to generate the basis for a release note.

Help

To recall this hints use gh-tag --help (or gh-tag -h).

Change log

v1.1 (04sep2013) {-}

PDF doc: gh-tag_v1.1.pdf

  • [new] Implement 2-factor-auth for GitHub token creation

v1.0 (04sep2013) {-}

PDF doc: gh-tag_v1.0.pdf

  • Initial release.
#!/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2013 https://gist.github.com/rbf
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
### File info:
GT_VERSION="v1.2-SNAPSHOT"
GT_GIST_ID="6434162"
GT_SOURCE="https://gist.github.com/rbf/${GT_GIST_ID}/raw/gh-tag"
GT_DOC="https://gist.github.com/rbf/${GT_GIST_ID}"
GT_INSTALL_PATH="/usr/local/bin/"
###
GT_COMMAND_DEFAULT_NAME=$(basename "${GT_SOURCE}")
GT_COMMAND_NAME="${0#${GT_INSTALL_PATH}}"
GT_COMMAND_NAME="${GT_COMMAND_NAME##/dev/fd/*}" # When using it in a piped mode, the pipe filename tends to be '/dev/fd/63'
GT_COMMAND_NAME="${GT_COMMAND_NAME:-${GT_COMMAND_DEFAULT_NAME}}"
GT_INSTALL_CURL="curl -sSL https://gist.github.com/rbf/${GT_GIST_ID}/raw/install"
GT_INSTALL_BASH_CURL="bash <(${GT_INSTALL_CURL})"
# Flags defaulted to false:
GT_ONLY_PRINT_RELEASE_NOTES=false
GT_ONLY_PRINT_RELEASE_NOTES_WITH_FULL_URL=false
GT_ONLY_PRINT_COMMITS=false
# Log functions
LOG_PREFIX_DEBUG="[DEBUG]"
LOG_PREFIX_INFO="[INFO] "
LOG_PREFIX_WARN="[WARN] "
LOG_PREFIX_ERROR="[ERROR]"
LOG_PREFIX_INPUT=" > "
GT_LOG_FILE="${GT_COMMAND_NAME}.log"
logblankline(){
echo >> ${GT_LOG_FILE}
}
log(){
echo $(date +"[%Y-%m-%d %H:%M:%S]") "$@" >> ${GT_LOG_FILE}
}
log-echo(){
echo "$@"
log "$@"
}
terminate(){
echo "${LOG_PREFIX_INFO} For detailed info look at file \"${GT_LOG_FILE}\""
logblankline
exit ${1}
}
github-request(){
GITHUB_REQUEST_LOG_MSG="${1}"
GITHUB_REQUEST="curl -isS ${2}"
GITHUB_REQUEST_NEEDS_LOGIN="${3}"
GITHUB_REQUEST_CALLBACK_ON_OK="${4}"
GITHUB_REQUEST_CALLBACK_ON_FAIL="${5}"
log
if [ "${GITHUB_REQUEST_NEEDS_LOGIN}" == "needs_login" ]
then
log-echo "${LOG_PREFIX_INFO} ${GITHUB_REQUEST_LOG_MSG}"
echo -n "${LOG_PREFIX_INPUT} "
GITHUB_REQUEST_SUCCESS_STATUS_OK="${LOG_PREFIX_INFO} OK"
GITHUB_REQUEST_SUCCESS_STATUS_FAILED="${LOG_PREFIX_ERROR} FAILED"
else
log "${LOG_PREFIX_INFO} ${GITHUB_REQUEST_LOG_MSG}"
echo -n "${LOG_PREFIX_INFO} ${GITHUB_REQUEST_LOG_MSG}"
GITHUB_REQUEST_SUCCESS_STATUS_OK="OK"
GITHUB_REQUEST_SUCCESS_STATUS_FAILED="\r${LOG_PREFIX_ERROR} ${GITHUB_REQUEST_LOG_MSG}FAILED"
fi
log ${LOG_PREFIX_DEBUG} ${GITHUB_REQUEST}
GITHUB_REQUEST_RESPONSE=$(eval ${GITHUB_REQUEST})
log "${LOG_PREFIX_DEBUG} ${GITHUB_REQUEST_RESPONSE}"
if [ "$(echo ${GITHUB_REQUEST_RESPONSE} | head -1 | grep "HTTP/1.1 2")" != "" ]
then
log "${LOG_PREFIX_INFO} ${GITHUB_REQUEST_LOG_MSG} OK"
echo "${GITHUB_REQUEST_SUCCESS_STATUS_OK}"
eval "${GITHUB_REQUEST_CALLBACK_ON_OK}"
else
GITHUB_REQUEST_RESPONSE_ERROR_MESSAGE="$(echo ${GITHUB_REQUEST_RESPONSE} | grep "\"message\": \"" | sed "s|.*\"message\": \"\(.*\)\".*|\1|")"
log "${LOG_PREFIX_ERROR} ${GITHUB_REQUEST_LOG_MSG} FAILED"
echo -e "${GITHUB_REQUEST_SUCCESS_STATUS_FAILED}"
log-echo "${LOG_PREFIX_ERROR} Reason: ${GITHUB_REQUEST_RESPONSE_ERROR_MESSAGE}"
eval "${GITHUB_REQUEST_CALLBACK_ON_FAIL}"
fi
}
updatescript(){
GT_INSTALLING_VERSION="$(eval "${GT_INSTALL_CURL}" | grep "GT_INSTALL_VERSION=" | head -1 | sed "s/GT_INSTALL_VERSION=\"\(.*\)\"/\1/")"
if [ "${GT_VERSION}" == "${GT_INSTALLING_VERSION}" ]
then
echo "${LOG_PREFIX_INFO} Already up-to-date."
exit 0
fi
echo "${LOG_PREFIX_INFO} ${GT_COMMAND_NAME} ${GT_VERSION}: There is a newer released version ${GT_INSTALLING_VERSION}."
read -p "${LOG_PREFIX_INPUT} Do you want to install '${GT_COMMAND_NAME} ${GT_INSTALLING_VERSION}'? [y/n] " GT_ANSWER
if [ "${GT_ANSWER:0:1}" != "y" ]
then
echo "${LOG_PREFIX_WARN} Update aborted by user."
exit 0
fi
eval ${GT_INSTALL_BASH_CURL}
}
printhelp(){
cat << EOF
Creates a tag for the current HEAD, and tries to suggest a meaningful tag message.
Usage: ${GT_COMMAND_NAME} [option] [<tag-name> [<access-token>]]
-c, --commits
Only print the log for the commits that have been done since the last
annotated tag. This might be useful to check what has been done since the
last release.
-n, --release-notes, --tag-message
Only print the text that would be used for the tag message, but without
actually creating the tag. This might be useful to generate the basis for
a release note.
-N
Like '-n' but including full permalinks to found issues, instead of only
the issue number prefixed with a '#' (which already makes them clickable
on the GitHub web interface).
--update
Check for a newer version of '${GT_COMMAND_NAME}' and if so, prompt to
install it, and exit.
<tag-name>
The name of the new tag to be created. If it is not specified, you will be
prompted to provide one.
<access-token>
The GitHub access token to query the issues mentioned in the commit messages.
The token can also be defined with a global variable named "GITHUB_ACCESS_TOKEN":
$ export GITHUB_ACCESS_TOKEN=<your-token>
If the token is not provided but it is needed (i.e. there are issues mentioned
in the commit messages), you will be prompted to generate one. Alternatively it
can be created in the GitHub setting page:
https://github.com/settings/applications
For more info visit ${GT_DOC}
EOF
}
if [ "${1}" == "--help" ] || [ "${1}" == "-h" ] || [ "${1}" == "-?" ]
then
printhelp
exit 0
elif [ "${1}" == "--version" ] || [ "${1}" == "-v" ]
then
echo "${GT_COMMAND_NAME} ${GT_VERSION}"
exit 0
elif [ "${1}" == "--update" ]
then
updatescript
exit
elif [ "${1}" == "--release-notes" ] || [ "${1}" == "--tag-message" ] || [ "${1}" == "-n" ]
then
GT_ONLY_PRINT_RELEASE_NOTES=true
shift
elif [ "${1}" == "-N" ]
then
GT_ONLY_PRINT_RELEASE_NOTES=true
GT_ONLY_PRINT_RELEASE_NOTES_WITH_FULL_URL=true
shift
elif [ "${1}" == "--commits" ] || [ "${1}" == "-c" ]
then
GT_ONLY_PRINT_COMMITS=true
shift
elif [ "${1:0:1}" == "-" ]
then
echo "${GT_COMMAND_NAME}: Invalid option ${1}"
echo "Main usage: ${GT_COMMAND_NAME} [-h | -v | -n | -N | -c] [<tag-name> [<access-token>]]"
echo "For more info type:"
echo " ${GT_COMMAND_NAME} --help"
exit 1
fi
[ -z "$(which git)" ] && echo "${GT_COMMAND_NAME}: It doesn't seem to be git installed in this system, or at least is not reachable in the PATH." && exit 1
GT_CURRENT_GIT_CONFIG_DIR=$(git rev-parse --git-dir 2> /dev/null)
[ -z "${GT_CURRENT_GIT_CONFIG_DIR}" ] && echo "${GT_COMMAND_NAME}: It doesn't seem to be git repo here." && exit 1
from_commit=$(git describe --abbrev=0 2> /dev/null)
if [ -z "${from_commit}" ]
then
from_commit="$(git log --format="%h" | tail -1)"
from_commit_type="initial commit"
GT_NO_TAGS_FOUND=true
else
from_commit_type="last annotated tag"
fi
to_commit="HEAD"
[ "$(git describe --always ${from_commit})" == "$(git describe --always ${to_commit})" ] && echo "${GT_COMMAND_NAME}: ${to_commit} has already been tagged as ${from_commit}. Nothing to do." && exit 1
GT_NEW_TAG_NAME=${1}
if [ -z "${GT_NEW_TAG_NAME}" ] && ! $GT_ONLY_PRINT_RELEASE_NOTES && ! $GT_ONLY_PRINT_COMMITS
then
GT_LAST_TAG=${from_commit}
GT_LAST_TAG_SUFFIX="${GT_LAST_TAG##*.}"
if [ -z "${GT_LAST_TAG_SUFFIX##*[!0-9]*}" ]
then
GT_SUGGESTED_NEW_TAG="v1.0"
else
GT_LAST_TAG_BASE="${GT_LAST_TAG%.*}"
let "GT_SUGGESTED_NEW_TAG_SUFFIX = GT_LAST_TAG_SUFFIX + 1"
GT_SUGGESTED_NEW_TAG="${GT_LAST_TAG_BASE}.${GT_SUGGESTED_NEW_TAG_SUFFIX}"
fi
[ $GT_NO_TAGS_FOUND ] && echo "${LOG_PREFIX_INFO} No tags found. This will be the first tag." || echo "${LOG_PREFIX_INFO} The ${from_commit_type} is '${GT_LAST_TAG}'."
read -p "${LOG_PREFIX_INPUT} New tag name [leave blank for '${GT_SUGGESTED_NEW_TAG}']: v" GT_NEW_TAG_NAME
if [ -z "${GT_NEW_TAG_NAME}" ]
then
GT_NEW_TAG_NAME="${GT_SUGGESTED_NEW_TAG}"
else
GT_NEW_TAG_NAME="v${GT_NEW_TAG_NAME}"
fi
fi
! $GT_ONLY_PRINT_RELEASE_NOTES && ! $GT_ONLY_PRINT_COMMITS && [ ! -z "$(git show ${GT_NEW_TAG_NAME} 2> /dev/null)" ] && echo "${LOG_PREFIX_ERROR} Tag '${GT_NEW_TAG_NAME}' already exists." && exit 1
GT_REPO="$(git config --get remote.origin.url)"
GT_REPO="${GT_REPO#https://gist.github.com/}"
GT_REPO="${GT_REPO#git://github.com/}" # Anonymously cloned repo
GT_REPO="${GT_REPO#[email protected]:}"
GT_REPO="${GT_REPO#[email protected]:}"
GT_REPO="${GT_REPO%.git}"
[ -z "${GT_REPO##*[!0-9]*}" ] && GT_REPO_IS_GIST="false" || GT_REPO_IS_GIST="true"
if ! ${GT_REPO_IS_GIST}
then
while read -r line
do
GT_COMMITS_WITH_ISSUES_MENTION+=("${line}")
done <<< "$(git log --color=never --format="%s" ${from_commit}..${to_commit} | grep "#" | sed "s|\(.* \([-_a-zA-Z0-9]*/*[-_a-zA-Z0-9]*#[0-9][0-9]*\).*\)|Issue \2: \1|" | sort) "
for commit in "${GT_COMMITS_WITH_ISSUES_MENTION[@]}"; do
commit="${commit#Issue }"
commit="${commit%%:*}"
GT_ISSUES+=("${commit}")
done
# Get list of unique issues:
GT_ISSUES=($(printf "%s\n" "${GT_ISSUES[@]}" | sort -u))
fi
if [ "${2}" != "" ]
then
GT_ACCESS_TOKEN="${2}"
else
GT_ACCESS_TOKEN="${GITHUB_ACCESS_TOKEN}" # Looking for a globally defined variable
fi
getgithubaccestoken(){
if [ "${GT_ACCESS_TOKEN}" == "" ]
then
echo "${LOG_PREFIX_INFO} A GitHub token is required to query the issues mentioned in the commit messages."
read -e -p "${LOG_PREFIX_INPUT} Access token [leave blank to create a new one]: " GT_ACCESS_TOKEN
fi
if [ "${GT_ACCESS_TOKEN}" == "" ]
then
GITHUB_USER=$(git config --get user.name)
read -e -p "${LOG_PREFIX_INPUT} GitHub user [leave blank to use '${GITHUB_USER}']: " input
GITHUB_USER="${input:-$GITHUB_USER}"
read -e -p "${LOG_PREFIX_INPUT} 2FA code [leave blank if not required]: " GITHUB_USER_2FA_CODE
[ "${GITHUB_USER_2FA_CODE}" != "" ] && GITHUB_2FA_HEADER="--header 'X-GitHub-OTP: ${GITHUB_USER_2FA_CODE}'" || unset GITHUB_2FA_HEADER
GT_ACCESS_TOKEN_REQUEST_BODY="{\"scopes\":[\"repo\"], \"note\":\"Generated on $(date +"%Y-%m-%d %H:%M:%S %z") by the script '${GT_COMMAND_NAME}' from ${GT_DOC}\"}"
github-request \
"Creating a new access token..." \
"-u ${GITHUB_USER} -d '${GT_ACCESS_TOKEN_REQUEST_BODY}' ${GITHUB_2FA_HEADER} https://api.github.com/authorizations" \
"needs_login" \
token_creation_callback_ok \
"terminate 1"
fi
github-request \
"Validating GitHub token... " \
"https://api.github.com/user?access_token=${GT_ACCESS_TOKEN}" \
"doesnt_need_login" \
"" \
token_validation_callback_failed
}
token_validation_callback_failed(){
log-echo "${LOG_PREFIX_ERROR} Token '${GT_ACCESS_TOKEN}' is not valid."
log-echo "${LOG_PREFIX_INFO} Generate a new token at https://github.com/settings/applications or relaunching this"
log-echo "${LOG_PREFIX_INFO} script leaving the token parameter blank and unsetting the global variable 'GITHUB_ACCESS_TOKEN'."
terminate 1
}
token_creation_callback_ok(){
GT_ACCESS_TOKEN=$(echo ${GITHUB_REQUEST_RESPONSE} | sed -e "s/.*\"token\": \"\([a-zA-Z0-9]*\)\".*/\1/")
GT_ACCESS_TOKEN_ID=$(echo ${GITHUB_REQUEST_RESPONSE} | sed -e "s/.*\"id\": \([0-9]*\).*/\1/")
echo "${LOG_PREFIX_INFO} New GitHub access token created successfully!"
echo "${LOG_PREFIX_INFO} You might save it for later usage in a global variable named GITHUB_ACCESS_TOKEN:"
echo "${LOG_PREFIX_INFO} export GITHUB_ACCESS_TOKEN=\"${GT_ACCESS_TOKEN}\""
log "${LOG_PREFIX_INFO} New token created successfully: ${GT_ACCESS_TOKEN} - Token id: ${GT_ACCESS_TOKEN_ID}"
}
getissuetitleandstate(){
issue_number="${1##*#}"
issue_repo="${1%%#*}"
issue_repo="${issue_repo:-${GT_REPO}}"
current_issue="$(curl -sSL https://api.github.com/repos/${issue_repo}/issues/${issue_number}?access_token=${GT_ACCESS_TOKEN})"
current_issue_title="$(echo "${current_issue}" | grep "\"title\"" | head -1)"
current_issue_title="${current_issue_title%,}"
current_issue_title="${current_issue_title##*: }"
current_issue_state="$(echo "${current_issue}" | grep "\"state\"" | head -1)"
current_issue_state="${current_issue_state%\",}"
current_issue_state="${current_issue_state##*\"}"
if ${GT_ONLY_PRINT_RELEASE_NOTES_WITH_FULL_URL}
then
echo " - https://github.com/${issue_repo}/issues/${issue_number}: ${current_issue_title} [${current_issue_state}]"
else
echo " - ${1}: ${current_issue_title} [${current_issue_state}]"
fi
}
GT_TAG_MESSAGE_TMP_FILE="/tmp/GT_TAG_MESSAGE_TMP_FILE.txt"
rm -f "${GT_TAG_MESSAGE_TMP_FILE}"
memonly(){
echo "$@" >> ${GT_TAG_MESSAGE_TMP_FILE}
}
memecho(){
echo "${LOG_PREFIX_INFO} $@"
memonly "$@"
}
[ $GT_NO_TAGS_FOUND ] && GT_COMMIT_COUNT=$(git rev-list ${to_commit} --count) || GT_COMMIT_COUNT=$(git rev-list ${from_commit}..${to_commit} --count)
if $GT_ONLY_PRINT_COMMITS
then
echo "${GT_COMMIT_COUNT} commit$([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "s") done since ${from_commit_type} (${from_commit}):"
git log --pretty=tformat:"%C(yellow)%h%Cgreen %ad %Creset| %s%C(red)%d %C(blue)[%an]%Creset" --graph --date=relative ${from_commit}..${to_commit}
exit
fi
if [ ${#GT_ISSUES[@]} -gt 0 ]
then
getgithubaccestoken
echo "${LOG_PREFIX_INFO} Querying GitHub repo '${GT_REPO}' about the$([ ${#GT_ISSUES[@]} -gt 1 ] && echo " ${#GT_ISSUES[@]}") issue$([ ${#GT_ISSUES[@]} -gt 1 ] && echo "s") mentioned in the"
echo "${LOG_PREFIX_INFO} $([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "${GT_COMMIT_COUNT}" || echo "only") commit$([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "s") done since ${from_commit_type} (${from_commit}):"
memonly "In the $([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "${GT_COMMIT_COUNT}" || echo "only") commit$([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "s") since ${from_commit_type} (${from_commit}) following issue$([ ${#GT_ISSUES[@]} -gt 1 ] && echo "s were" || echo " was") mentioned:"
memonly
for issue in "${GT_ISSUES[@]}"
do
memecho "$(getissuetitleandstate ${issue})"
done
else
memecho "${GT_COMMIT_COUNT} commit$([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "s") done since ${from_commit_type} (${from_commit})."
fi
if ! $GT_ONLY_PRINT_RELEASE_NOTES
then
GT_MESSAGE_EDITOR="$(git config --get core.editor || which vim || which vi || which nano)"
memonly ""
memonly "# You might want to modify the tag message here. Lines starting "
memonly "# with '#' will be ignored, but an empty message *DOES NOT* abort the tag."
memonly "# "
memonly "# "
memonly "# ${GT_COMMIT_COUNT} commit$([ ${GT_COMMIT_COUNT} -gt 1 ] && echo "s") done since ${from_commit_type} (${from_commit}):"
memonly "# "
while read -r line
do
memonly "# ${line}"
done <<< "$(git log --color=never --format="%h | %s%d [%an]" --graph ${from_commit}..${to_commit})"
${GT_MESSAGE_EDITOR} ${GT_TAG_MESSAGE_TMP_FILE}
echo -n "${LOG_PREFIX_INFO} Creating tag '${GT_NEW_TAG_NAME}'... "
GT_TAG_COMMAND="git tag -a --file=${GT_TAG_MESSAGE_TMP_FILE} ${GT_NEW_TAG_NAME}"
eval "${GT_TAG_COMMAND}"
[ ! $? -eq 0 ] && echo "${LOG_PREFIX_ERROR} Oups, the tag wasn't created!" && exit 1
echo "OK"
if [ "${GT_REPO}" != "" ] && [ ${GT_REPO_IS_GIST} == "false" ]
then
if ${GT_REPO_IS_GIST}
then
echo "${LOG_PREFIX_INFO} To push the new tag to GitHub use 'git push --tags'."
else
echo "${LOG_PREFIX_INFO} After pushing the new tag (with 'git push --tags'), you might:"
echo "${LOG_PREFIX_INFO} - visit following permalink to see it on GitHub:"
echo "${LOG_PREFIX_INFO} https://github.com/${GT_REPO}/releases/tag/${GT_NEW_TAG_NAME}"
echo "${LOG_PREFIX_INFO} - visit following permalink to compare it with the previous tag:"
echo "${LOG_PREFIX_INFO} https://github.com/${GT_REPO}/compare/${from_commit}...${GT_NEW_TAG_NAME}"
fi
fi
fi
exit 0
Display the source blob
Display the rendered blob
Raw
#!/bin/bash
# The MIT License (MIT)
#
# Copyright (c) 2013 https://gist.github.com/rbf
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
GT_INSTALL_VERSION="v1.1"
GT_INSTALL_BLOB_HASH="135a6e78023a5c27ac00b3dc7c550b54b99b04f3"
GT_INSTALL_DIR="/usr/local/bin"
https://gist.github.com/rbf/6434162/raw/gh-tag
GT_INSTALL_TOOL_NAME="gh-tag"
GT_INSTALL_GIST_ID="6434162"
GT_INSTALL_URL="https://gist.github.com/rbf/${GT_INSTALL_GIST_ID}/${GT_INSTALL_BLOB_HASH}/${GT_INSTALL_TOOL_NAME}"
if [ ! -d "${GT_INSTALL_DIR}" ]
then
echo "Install directory '${GT_INSTALL_DIR}' does not exist. Creating it..."
ORIG_USER="$(whoami)" && \
sudo mkdir -p ${GT_INSTALL_DIR} && \
sudo chown -R "${ORIG_USER}" ${GT_INSTALL_DIR} && \
echo "Install directory '${GT_INSTALL_DIR}' created successfully!" || \
echo "Oups! Something went wrong when trying to create the install directory '${GT_INSTALL_DIR}'."
fi
echo "Installing '${GT_INSTALL_TOOL_NAME} ${GT_INSTALL_VERSION}' from '${GT_INSTALL_URL}' to '${GT_INSTALL_DIR}'..."
curl -L ${GT_INSTALL_URL} > "${GT_INSTALL_DIR}/${GT_INSTALL_TOOL_NAME}" && \
chmod +x "${GT_INSTALL_DIR}/${GT_INSTALL_TOOL_NAME}" && \
${GT_INSTALL_TOOL_NAME} --version || \
echo "Oups! Something went wrong when installing ${GT_INSTALL_TOOL_NAME}."
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment