From eef5ded6d6e5b949a3f1c7c61288b5474478a3b9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 15 Jan 2023 00:48:40 +0000 Subject: [PATCH] feat: add version subcommand and bump command --- bump.sh | 40 ++++++++++++++++++++++++++++++++++++++++ duckdns.sh | 11 +++++++++++ 2 files changed, 51 insertions(+) create mode 100755 bump.sh diff --git a/bump.sh b/bump.sh new file mode 100755 index 0000000..1f1076e --- /dev/null +++ b/bump.sh @@ -0,0 +1,40 @@ +#!/bin/sh +set -e +set -u + +my_version="${1-}" +if [ -z "${my_version}" ]; then + echo "Usage: bump.sh v1.2.3" + exit 1 +fi + +if ! git diff --quiet; then + echo "Error: git status is dirty" +fi + +if ! command -v sd > /dev/null; then + echo "Install 'sd' first." + echo " curl https://webi.sh/sd | sh" + exit 1 +fi + +my_commit_hash="$( + git rev-parse --short HEAD +)" +my_commit_date="$( + git show -s --format=%ci "${my_commit_hash}" | + grep -E '20[0-9]{2}-[01][0-9]-[0123][0-9]' +)" +my_year="$( + date '+%Y' +)" + +sd 'my_version=.*' "my_version='${my_version}'" duckdns.sh +sd 'my_year=.*' "my_year='${my_year}'" duckdns.sh +sd 'my_date=.*' "my_date='${my_commit_date}'" duckdns.sh + +git add ./duckdns.sh +git commit -m "chore(release): bump to ${my_version}" +git tag "${my_version}" + +git describe --tags diff --git a/duckdns.sh b/duckdns.sh index 9a7cd58..70905b7 100755 --- a/duckdns.sh +++ b/duckdns.sh @@ -201,6 +201,15 @@ cmd_update() { ( fn_update_ips ); } +cmd_version() { ( + my_year='0000' + my_version='v0.0.0' + my_date='0000-00-00' + + echo "DuckDNS.sh ${my_version} (${my_date})" + echo "Copyright ${my_year} AJ ONeal" +); } + fn_check_env() { ( if ! [ -e ~/.config/duckdns.sh/"${DUCKDNS_SH_SUBDOMAIN}.env" ]; then exit 1 @@ -447,6 +456,7 @@ main() { ( update) cmd_update ;; __noop__) ;; help | --help | -h) fn_help ;; + version | --version | -V) cmd_version ;; *) fn_help exit 1 @@ -473,6 +483,7 @@ fn_help() { ( echo " disable - disable on boot or login" echo "" echo " help - show this menu" + echo " version - show version and exit" echo "" ); }