summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziggys <ziggys@autistici.org>2018-07-13 18:23:44 -0400
committerziggys <ziggys@autistici.org>2018-07-13 18:23:44 -0400
commitc4b1d039a2c8e32e4ca4c4f7294d6132e6ab1de3 (patch)
tree97e287eded6bed08a3a1c94016016f80b3ee6dae
downloadsnippets-c4b1d039a2c8e32e4ca4c4f7294d6132e6ab1de3.tar
snippets-c4b1d039a2c8e32e4ca4c4f7294d6132e6ab1de3.zip
add bump-version.sh
-rwxr-xr-xbump-version.sh167
-rwxr-xr-xhead.sh45
-rwxr-xr-xtist.sh45
-rwxr-xr-xtist2.sh45
4 files changed, 302 insertions, 0 deletions
diff --git a/bump-version.sh b/bump-version.sh
new file mode 100755
index 0000000..7990825
--- /dev/null
+++ b/bump-version.sh
@@ -0,0 +1,167 @@
+#!/bin/sh
+# -*- ENCODING: UTF-8 -*-
+# bump-version.sh - script name
+# a script to update version numbers in git projects
+# Author: ziggys
+# This piece of software is released to Public Domain
+
+# scriptinfo
+SCRIPTNAME="${0##*/}"
+SCRIPTNAME="${SCRIPTNAME%%.sh}"
+VERSION="0.0.1" # create snippet
+AUTHOR="ziggys"
+LICENSE="Public Domain"
+
+# usage
+usage () {
+test "$#" = 0 || printf "%s %s\\n" "${SCRIPTNAME}" "$@"
+cat << EOF | fold -s
+${SCRIPTNAME} version ${VERSION}
+ by ${AUTHOR}
+ License: ${LICENSE}
+
+${SCRIPTNAME} is a shellscript to bump version numbers in git projects.
+
+Usage: ${SCRIPTNAME} [option] <args>
+Usage: ${SCRIPTNAME} [-|-b] <args>
+ or: ${SCRIPTNAME} -h
+
+Options
+ patch <version> Bump to new patch <version>
+ minor <version> Bump to new minor <version>
+ mayor <release> Bump to new mayor <release>
+ -h HELP Print this help and exit
+
+For more details about this script go to
+Official Repository: https://git.p4g.club/git/${SCRIPTNAME}.git
+Mirror Repository: https://gitgud.io/ziggys/${SCRIPTNAME}.git
+EOF
+exit 0
+}
+
+# use a file to describe new version
+describe_usefile () {
+DESCRIBEF="$(mktemp -p "${TMPDIR}")"
+printf "\\n/* Write a version description, save the file and close %s\\n \
+ /* Description will be added to VERSION notice in %s\\n \
+ /* Lines starting with '/*' will be ignored\\n \
+ /* Leave it 'blank' if you won't like a version description\\n" \
+ "${EDITOR:=vim}" "${VFILE}" > "${DESCRIBEF}"
+
+ sed -i 's/^ *//g' "${DESCRIBEF}"
+ ${EDITOR} "${DESCRIBEF}"
+ DESCRIPTION="$(sed '/^\/\*/ d' "${DESCRIBEF}")"
+
+ test -z "${DESCRIPTION}" \
+ && printf "Version will be described from default" \
+ && DESCRIPTION="version ${NEXT}"
+}
+
+# obtain current version
+TMPDIR="$(mktemp -d)"
+VFILE="$2"
+CURRENT="$(sed '/^VERSION=/ !d; s/VERSION="//; s/".*$//' "${VFILE}")"
+
+if [ -z "${CURRENT}" ]; then
+ printf "%s couldn't find version number in %s\\n" "${SCRIPTNAME}" "${VFILE}"
+ printf "Please, edit %s or use a file containing a valid string VERSION=\"x.y.z\"" "${VFILE}"
+ exit 0
+else
+ printf "Current version is: %s\\n" "${CURRENT}"
+fi
+
+# calculate new version
+case "$1" in
+ -p | --patch)
+ NEXT="$(echo "${CURRENT}" | \
+ awk '{split($0,a,".");
+ a[3]++;
+ b=a[1]"."a[2]"."a[3]}
+ END{OFS="."; print b}
+ ')"
+
+ printf "Patch version will be: %s\\n" "${NEXT}"
+ ;;
+
+ -u | --update)
+ NEXT="$(echo "${CURRENT}" | \
+ awk '{split($0,a,".");
+ a[2]++;
+ b=a[1]"."a[2]"."0}
+ END{OFS="."; print b}
+ ')"
+
+ printf "Update version will be: %s\\n" "${NEXT}"
+ ;;
+
+ -r | --release)
+ NEXT="$(echo "${CURRENT}" | \
+ awk '{split($0,a,".");
+ a[1]++;
+ b=a[1]"."0"."0}
+ END{OFS="."; print b}
+ ')"
+
+ NTAG="v${NEXT}"
+
+ printf "Release version will be: %s\\n" "${NEXT}"
+ printf "Release tag will be: %s\\n" "${NTAG}"
+ ;;
+
+ -c | --custom)
+ printf "Please, provide a valid version number (x.y.z): "
+ read -r CNEXT
+
+ NEXT="${CNEXT}"
+ printf "Next version will be: %s\\n" "${NEXT}"
+ ;;
+
+ *) usage "$@" ;;
+esac
+
+# describe new version for commit and tag
+case "$3" in
+ -m | --message ) DESCRIPTION="$4" ;;
+ *) describe_usefile ;;
+esac
+
+# bump version
+sed -i '/^VERSION=/ s/'"${CURRENT}"'/'"${NEXT}"'/' "${VFILE}"
+sed -i '/^VERSION=/ s/# .*$/# '"${DESCRIPTION}"'/' "${VFILE}"
+
+# commit changes
+printf "Would you like to commit changes in %s? (yes/all/no): " "${VFILE}"
+read -r CCOMMIT
+
+case "${CCOMMIT}" in
+ y | yes | Y | YES | Yes )
+ printf "\\nAdding %s to stage and commiting changes" "${VFILE}"
+ git add "${VFILE}"
+ git commit -m "${DESCRIPTION}"
+ ISTAG="${NTAG}"
+ ;;
+ a | all | A | ALL | All )
+ FILES="$(find . | grep -v "git" | sed 's/.\///g; 1 d')"
+ for file in $FILES; do
+ sed -i '/^VERSION=/ s/'"${CURRENT}"'/'"${NEXT}"'/' "${file}"
+ sed -i '/^VERSION=/ s/# .*$/# '"${DESCRIPTION}"'/' "${file}"
+ done
+
+ printf "\\nAdding\\n%s\\nto stage and commiting changes\\n" "${FILES}"
+ git add .
+ git commit -m "${DESCRIPTION}"
+ ISTAG="${NTAG}"
+ ;;
+ n | no | N | NO | No )
+ printf "\\nNo files will be added to stage nor commited"
+ ;;
+esac
+
+# tag if needed
+if [ ! -z "${ISTAG}" ]; then
+ CHASH="$(git log --pretty=format:'%h' -n 1)"
+ git tag -a "${NTAG}" "${CHASH}" -m "${DESCRIPTION}"
+fi
+
+rm -rf "${TMPDIR}"
+exit 0
diff --git a/head.sh b/head.sh
new file mode 100755
index 0000000..9128d03
--- /dev/null
+++ b/head.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# -*- ENCODING: UTF-8 -*-
+# FIXME: change script slug, full name and description
+# head - script name
+# description
+# Author: ziggys
+# License: The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)
+
+# scriptinfo
+SCRIPTNAME="${0##*/}"
+SCRIPTNAME="${SCRIPTNAME%%.sh}"
+#FIXME: add version, author and license if needed
+VERSION="" # versionando versionando
+AUTHOR=""
+LICENSE=""
+
+# usage
+#FIXME: "edit all this to fit your fitness"
+usage () {
+test "${#}" = 0 || printf "%s %s\\n "${SCRIPTNAME} "${@}"
+cat << EOF | fold -s
+${SCRIPTNAME} version ${VERSION}
+ by ${AUTHOR}
+ License: ${LICENSE}
+
+#FIXME: script description and usage options
+${SCRIPTNAME} is a
+
+Usage: ${SCRIPTNAME} [options] <args>
+Usage: ${SCRIPTNAME} [-a|-b] <args>
+ or: ${SCRIPTNAME} -h
+ or: ...
+
+Options
+ -a <args> A description
+ -b <BARGS> B description
+ -h HELP Print this help and exit
+
+For more details about this script go to
+Official Repository:
+Mirror Repository:
+EOF
+exit 0
+}
+
diff --git a/tist.sh b/tist.sh
new file mode 100755
index 0000000..793aa58
--- /dev/null
+++ b/tist.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# -*- ENCODING: UTF-8 -*-
+# FIXME: change script slug, full name and description
+# head - script name
+# description
+# Author: ziggys
+# License: The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)
+
+# scriptinfo
+SCRIPTNAME="${0##*/}"
+SCRIPTNAME="${SCRIPTNAME%%.sh}"
+#FIXME: add version, author and license if needed
+VERSION="0.3.0" # versionando versionando
+AUTHOR=""
+LICENSE=""
+
+# usage
+#FIXME: "edit all this to fit your fitness"
+usage () {
+test "${#}" = 0 || printf "%s %s\\n "${SCRIPTNAME} "${@}"
+cat << EOF | fold -s
+${SCRIPTNAME} version ${VERSION}
+ by ${AUTHOR}
+ License: ${LICENSE}
+
+#FIXME: script description and usage options
+${SCRIPTNAME} is a
+
+Usage: ${SCRIPTNAME} [options] <args>
+Usage: ${SCRIPTNAME} [-a|-b] <args>
+ or: ${SCRIPTNAME} -h
+ or: ...
+
+Options
+ -a <args> A description
+ -b <BARGS> B description
+ -h HELP Print this help and exit
+
+For more details about this script go to
+Official Repository:
+Mirror Repository:
+EOF
+exit 0
+}
+
diff --git a/tist2.sh b/tist2.sh
new file mode 100755
index 0000000..793aa58
--- /dev/null
+++ b/tist2.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# -*- ENCODING: UTF-8 -*-
+# FIXME: change script slug, full name and description
+# head - script name
+# description
+# Author: ziggys
+# License: The Drunken BEER License v 1.1 (https://git.p4g.club/git/beer/about)
+
+# scriptinfo
+SCRIPTNAME="${0##*/}"
+SCRIPTNAME="${SCRIPTNAME%%.sh}"
+#FIXME: add version, author and license if needed
+VERSION="0.3.0" # versionando versionando
+AUTHOR=""
+LICENSE=""
+
+# usage
+#FIXME: "edit all this to fit your fitness"
+usage () {
+test "${#}" = 0 || printf "%s %s\\n "${SCRIPTNAME} "${@}"
+cat << EOF | fold -s
+${SCRIPTNAME} version ${VERSION}
+ by ${AUTHOR}
+ License: ${LICENSE}
+
+#FIXME: script description and usage options
+${SCRIPTNAME} is a
+
+Usage: ${SCRIPTNAME} [options] <args>
+Usage: ${SCRIPTNAME} [-a|-b] <args>
+ or: ${SCRIPTNAME} -h
+ or: ...
+
+Options
+ -a <args> A description
+ -b <BARGS> B description
+ -h HELP Print this help and exit
+
+For more details about this script go to
+Official Repository:
+Mirror Repository:
+EOF
+exit 0
+}
+