From 13c03cac197b56cf1a3cb58c8e0f9f99aeaa663f Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sun, 29 Jan 2017 13:12:02 +0100 Subject: [PATCH 1/7] Added sample usage output --- Readme.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 2d523fe..6d858ed 100644 --- a/Readme.md +++ b/Readme.md @@ -79,7 +79,68 @@ The script guides you through all 5 steps of the beside the tag are required.** Follow the instructions and you are good to go. ```bash -$ gpgit 1.0.0 +$ gpgit 1.1.3 +==> 1. Generate new GPG key + Key already generated. Using key: 97312D5EB9D7AE7D0BD4307351DAE9B7C1AE9161 +==> 2. Publish your key + Assuming key was already published after its creation. If not please do so. +==> 3. Usage of GPG by git + -> 3.1 Configure git GPG key + Git already configured with your GPG key + -> 3.2 Commit signing + Commit signing already enabled. + -> 3.3 Create signed git tag + Refreshing tags from upstream. + Continue? [Y/n]y +Already up-to-date. + Creating signed tag 1.1.3 and pushing it to the remote git. + Continue? [Y/n]y +Counting objects: 1, done. +Writing objects: 100% (1/1), 794 bytes | 0 bytes/s, done. +Total 1 (delta 0), reused 0 (delta 0) +To github.com:NicoHood/gpgit.git + * [new tag] 1.1.3 -> 1.1.3 +==> 4. Creation of a signed compressed release archive + -> 4.0 Download archive from online source + Downloading source from URL https://github.com/NicoHood/gpgit/archive/1.1.3.tar.gz + Continue? [Y/n]y +--2017-01-29 13:05:43-- https://github.com/NicoHood/gpgit/archive/1.1.3.tar.gz +Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113 +Connecting to github.com (github.com)|192.30.253.112|:443... connected. +HTTP request sent, awaiting response... 302 Found +Location: https://codeload.github.com/NicoHood/gpgit/tar.gz/1.1.3 [following] +--2017-01-29 13:05:43-- https://codeload.github.com/NicoHood/gpgit/tar.gz/1.1.3 +Resolving codeload.github.com (codeload.github.com)... 192.30.253.121, 192.30.253.120 +Connecting to codeload.github.com (codeload.github.com)|192.30.253.121|:443... connected. +HTTP request sent, awaiting response... 200 OK +Length: unspecified [application/x-gzip] +Saving to: '/hackallthethings/gpgit/archive/gpgit-1.1.3.tar.gz' + +/hackallthethings/gpgit/archive/gpgit-1.1.3.tar.gz [ <=> ] 10.90K --.-KB/s in 0.001s + +2017-01-29 13:05:44 (8.16 MB/s) - '/hackallthethings/gpgit/archive/gpgit-1.1.3.tar.gz' saved [11162] + + -> 4.1 Create compressed archive + Archive /hackallthethings/gpgit/archive/gpgit-1.1.3.tar.gz already exists. + Verifying git against local source. + Continue? [Y/n]y + Existing archive successfully verified against local source. + -> 4.2 Create message digest + Creating message digest /hackallthethings/gpgit/archive/gpgit-1.1.3.tar.gz.sha512 + Continue? [Y/n]y + -> 4.3 Sign the sources + Creating signature /hackallthethings/gpgit/archive/gpgit-1.1.3.tar.gz.sig + Continue? [Y/n]y +==> 5. Upload the release + -> 5.1 Github + Uploading to Github. Please setup a Github token first: + (Github->Settings->Personal access tokens; public repo access) + Continue? [Y/n]y + Enter your Github token: + Github release created. + Signature uploaded. + Message digest uploaded. +==> Finished without errors ``` For additional tweaks you may use some optional parameters: From c428ed0a725816eb9a880cc800bbed5a5b15f96c Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 11 Feb 2017 12:29:36 +0100 Subject: [PATCH 2/7] Trap on errors --- gpgit.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gpgit.sh b/gpgit.sh index 51969c5..b28934a 100755 --- a/gpgit.sh +++ b/gpgit.sh @@ -1,8 +1,5 @@ #!/bin/bash -# Stop on errors -set -e -u -o pipefail - # Avoid any encoding problems export LANG=C @@ -47,6 +44,22 @@ usage() # Functions ################################################################################ +function error_exit +{ + error "Exited due to error." + exit 1 +} + +function kill_exit +{ + error "Exited due to user intervention." + exit 1 +} + +# Trap errors +trap error_exit ERR +trap kill_exit SIGTERM SIGINT + # Check if messages are to be printed using color unset ALL_OFF BOLD BLUE GREEN RED YELLOW if [[ -t 2 ]]; then From 046aa4a6f200edce23577959dea0020d94b61b8e Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 11 Feb 2017 12:30:21 +0100 Subject: [PATCH 3/7] Move and rename functions --- gpgit.sh | 58 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/gpgit.sh b/gpgit.sh index b28934a..f216c67 100755 --- a/gpgit.sh +++ b/gpgit.sh @@ -7,7 +7,27 @@ shopt -s extglob PROGNAME=$(basename "$0") -usage() +################################################################################ +# Functions +################################################################################ + +function error_exit +{ + error "Exited due to error." + exit 1 +} + +function kill_exit +{ + error "Exited due to user intervention." + exit 1 +} + +# Trap errors +trap error_exit ERR +trap kill_exit SIGTERM SIGINT + +function usage() { echo "Usage: ${PROGNAME} [options]" echo @@ -40,26 +60,6 @@ usage() echo '-y, --yes Assume "yes" on all questions.' } -################################################################################ -# Functions -################################################################################ - -function error_exit -{ - error "Exited due to error." - exit 1 -} - -function kill_exit -{ - error "Exited due to user intervention." - exit 1 -} - -# Trap errors -trap error_exit ERR -trap kill_exit SIGTERM SIGINT - # Check if messages are to be printed using color unset ALL_OFF BOLD BLUE GREEN RED YELLOW if [[ -t 2 ]]; then @@ -82,37 +82,37 @@ if [[ -t 2 ]]; then fi readonly ALL_OFF BOLD BLUE GREEN RED YELLOW -msg() { +function msg() { local mesg=$1; shift printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } -msg2() { +function msg2() { local mesg=$1; shift printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } -plain() { +function plain() { local mesg=$1; shift printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } -warning() { +function warning() { local mesg=$1; shift printf "${YELLOW}==> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } -error() { +function error() { local mesg=$1; shift printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } -info() { +function info() { local mesg=$1; shift printf "${YELLOW}[!]:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } -gpgit_yesno() { +function gpgit_yesno() { [[ "${config[YES]}" == true ]] && return while read -r -t 0; do read -r; done read -rp "${BOLD} Continue? [Y/n]${ALL_OFF}" yesno @@ -122,7 +122,7 @@ gpgit_yesno() { fi } -gpgit_check_tool() { +function gpgit_check_tool() { if ! command -v "$1" &> /dev/null; then error "Required tool $1 not found. Please check your PATH variable or install the missing dependency." exit 1 From 8193d378fe118471ce543599d67977d1e2ca6606 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 11 Feb 2017 13:24:46 +0100 Subject: [PATCH 4/7] Fix and extend traps --- gpgit.sh | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/gpgit.sh b/gpgit.sh index f216c67..af99a70 100755 --- a/gpgit.sh +++ b/gpgit.sh @@ -11,22 +11,6 @@ PROGNAME=$(basename "$0") # Functions ################################################################################ -function error_exit -{ - error "Exited due to error." - exit 1 -} - -function kill_exit -{ - error "Exited due to user intervention." - exit 1 -} - -# Trap errors -trap error_exit ERR -trap kill_exit SIGTERM SIGINT - function usage() { echo "Usage: ${PROGNAME} [options]" @@ -112,6 +96,27 @@ function info() { printf "${YELLOW}[!]:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2 } +function error_exit +{ + local parent_lineno="$1" + local message="$2" + local code="${3:-1}" + if [[ -n "${message}" ]] ; then + error "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}" + else + error "Error on or near line ${parent_lineno}; exiting with status ${code}" + fi + plain "Please report this error with the full bash output to:" + plain "https://github.com/NicoHood/gpgit/issues" + exit "${code}" +} + +function kill_exit +{ + error "Exited due to user intervention." + exit 1 +} + function gpgit_yesno() { [[ "${config[YES]}" == true ]] && return while read -r -t 0; do read -r; done @@ -133,6 +138,10 @@ function gpgit_check_tool() { # Parameters ################################################################################ +# Trap errors +trap 'error_exit ${LINENO}' ERR +trap kill_exit SIGTERM SIGINT + # Check for gpg version if ! gpg --version | grep "gpg (GnuPG) 2" -q; then error "No gpg version 2.x available. Please install the newest gpg version." From 99963c3a23d022e74722bed409c5f545400f0869 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 11 Feb 2017 17:45:57 +0100 Subject: [PATCH 5/7] Added more colors --- gpgit.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gpgit.sh b/gpgit.sh index af99a70..e573497 100755 --- a/gpgit.sh +++ b/gpgit.sh @@ -45,7 +45,7 @@ function usage() } # Check if messages are to be printed using color -unset ALL_OFF BOLD BLUE GREEN RED YELLOW +unset ALL_OFF BOLD BLUE GREEN RED YELLOW MAGENTA CYAN if [[ -t 2 ]]; then # prefer terminal safe colored and bold text when tput is supported if tput setaf 0 &>/dev/null; then @@ -55,6 +55,8 @@ if [[ -t 2 ]]; then GREEN="${BOLD}$(tput setaf 2)" RED="${BOLD}$(tput setaf 1)" YELLOW="${BOLD}$(tput setaf 3)" + MAGENTA="${BOLD}$(tput setaf 5)" + CYAN="${BOLD}$(tput setaf 6)" else ALL_OFF="\e[1;0m" BOLD="\e[1;1m" @@ -62,9 +64,11 @@ if [[ -t 2 ]]; then GREEN="${BOLD}\e[1;32m" RED="${BOLD}\e[1;31m" YELLOW="${BOLD}\e[1;33m" + MAGENTA="${BOLD}\e[1;35m" + CYAN="${BOLD}\e[1;36m" fi fi -readonly ALL_OFF BOLD BLUE GREEN RED YELLOW +readonly ALL_OFF BOLD BLUE GREEN RED YELLOW MAGENTA CYAN function msg() { local mesg=$1; shift From b5092aa48f22dac42377d75eb923d836cd8e460f Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 11 Feb 2017 17:47:13 +0100 Subject: [PATCH 6/7] Small corrections --- gpgit.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gpgit.sh b/gpgit.sh index e573497..f41516c 100755 --- a/gpgit.sh +++ b/gpgit.sh @@ -4,8 +4,10 @@ export LANG=C shopt -s extglob +set -u PROGNAME=$(basename "$0") +VERSION=1.2.0 ################################################################################ # Functions @@ -13,6 +15,7 @@ PROGNAME=$(basename "$0") function usage() { + echo "${PROGNAME} ${VERSION}" echo "Usage: ${PROGNAME} [options]" echo echo 'Mandatory parameters:' @@ -144,7 +147,7 @@ function gpgit_check_tool() { # Trap errors trap 'error_exit ${LINENO}' ERR -trap kill_exit SIGTERM SIGINT +trap kill_exit SIGTERM SIGINT SIGHUP # Check for gpg version if ! gpg --version | grep "gpg (GnuPG) 2" -q; then From 08045c046d0559bc7d66f08a4db5c6258cbde032 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Mon, 24 Apr 2017 22:36:54 +0200 Subject: [PATCH 7/7] Release 1.2.0 --- Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Readme.md b/Readme.md index 4e0060a..4b813bf 100644 --- a/Readme.md +++ b/Readme.md @@ -369,6 +369,13 @@ with [enigmail and thunderbird](https://wiki.archlinux.org/index.php/thunderbird ## Version History ``` +1.2.0 (24.04.2017) +* Trap on errors +* Detect gpg2 +* Fix git tags pull/push +* Small code fixes +* Thanks @cmaglie with #3 + 1.1.2 (22.01.2017) * Fixed Github uploading name