Skip to content

Commit

Permalink
Merge pull request #126 from lalyos/version-updater-script
Browse files Browse the repository at this point in the history
Add script for aiming tedious tasks for a new minor consul release
  • Loading branch information
progrium committed Jan 14, 2016
2 parents fb2c946 + 4a93d60 commit 27e7958
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 0.6/consul/update_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -eo pipefail
[[ "$TRACE" ]] && set -x || :

debug() {
[[ "$DEBUG" ]] && echo "-----> $*" 1>&2
}

consul_version() {
sed -n "s/ENV CONSUL_VERSION //p" Dockerfile
}

next_version() {
debug "new version will be calculated ..."
local oldVersion=$(consul_version)
debug "oldVersion: $oldVersion"
echo ${oldVersion%.*}.$((${oldVersion##*.} + 1))
}

update_dockerfile() {
declare ver=${1:? required}

local sha=$(curl -Ls https://releases.hashicorp.com/consul/${ver}/consul_${ver}_SHA256SUMS | sed -n "s/ .*linux_amd64.*//p")
debug "sha=$sha"

sed -i "s/\(ENV CONSUL_VERSION\) .*/\1 $newVersion/;s/\(ENV CONSUL_SHA256\) .*/\1 $sha/" Dockerfile
}

main() {
declare desc="Updates Dockerfile url/sha for the provided version, or calculates next patch version if called without params"
declare newVersion=${1:-$(next_version)}

debug "newVersion=$newVersion"
update_dockerfile $newVersion
git diff
echo "=====> Now you can run: git commit -am 'Upgrade Consul to $newVersion'"
}

[[ "$0" == "$BASH_SOURCE" ]] && main "$@" || :

0 comments on commit 27e7958

Please sign in to comment.