Skip to content

Commit

Permalink
Merge pull request #4 from NicoHood/fixes
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
NicoHood committed May 12, 2017
2 parents 21400f5 + 08045c0 commit ae2dd99
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 19 deletions.
70 changes: 69 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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:
Expand Down Expand Up @@ -308,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
Expand Down
65 changes: 47 additions & 18 deletions gpgit.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#!/bin/bash

# Stop on errors
set -e -u -o pipefail

# Avoid any encoding problems
export LANG=C

shopt -s extglob
set -u

PROGNAME=$(basename "$0")
VERSION=1.2.0

################################################################################
# Functions
################################################################################

usage()
function usage()
{
echo "${PROGNAME} ${VERSION}"
echo "Usage: ${PROGNAME} <tag> [options]"
echo
echo 'Mandatory parameters:'
Expand Down Expand Up @@ -43,12 +47,8 @@ usage()
echo '-y, --yes Assume "yes" on all questions.'
}

################################################################################
# Functions
################################################################################

# 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
Expand All @@ -58,48 +58,73 @@ 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"
BLUE="${BOLD}\e[1;34m"
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

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 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
read -rp "${BOLD} Continue? [Y/n]${ALL_OFF}" yesno
Expand All @@ -109,7 +134,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
Expand All @@ -120,6 +145,10 @@ gpgit_check_tool() {
# Parameters
################################################################################

# Trap errors
trap 'error_exit ${LINENO}' ERR
trap kill_exit SIGTERM SIGINT SIGHUP

# Check for gpg version. On some distribution gpg 2.x is installed as gpg2.
if ! gpg --version | grep "gpg (GnuPG) 2" -q; then
if ! gpg2 --version | grep "gpg (GnuPG) 2" -q; then
Expand Down

0 comments on commit ae2dd99

Please sign in to comment.