From a4c62c2221432e44b8f010ed7c0a9e4070d5bbd2 Mon Sep 17 00:00:00 2001 From: Alexander Weinhold Date: Sat, 9 Jun 2018 18:26:09 +0200 Subject: [PATCH] add gitdist for release distribution --- gitdist | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 gitdist diff --git a/gitdist b/gitdist new file mode 100755 index 0000000..c9de63a --- /dev/null +++ b/gitdist @@ -0,0 +1,45 @@ +#!/bin/bash + +################################### +# gitdist packs zip archives and # +# copies them to a remote server # +################################### + +example='projectName=spameggs +sshUserHost="foo@bar.org" +sshPort=22 +releaseFolder=/srv/releases +files="binary1 binary2 readme.md"' + +source .gitdist || { echo "you need a .gitdist file in your git repo"; exit 1; } + +if [ -z "$projectName" ] || [ -z "$sshUserHost" ] || [ -z "$sshPort" ] || [ -z "$releaseFolder" ] || [ -z "$files" ]; then + echo '.gitdist does not provide all necessary variables' + echo "example of a .gitdist file:" + echo + echo "$example" + exit 1 +fi + +timestamp=`date +"%Y%m%d-%H%M"` +currentBranch=`git rev-parse --abbrev-ref HEAD` + +if [ "$currentBranch" = "master" ]; then + zipfile="$projectName-$timestamp.zip" + setCurrent=true +else + zipfile="$projectName-$currentBranch-$timestamp.zip" +fi +echo "zipfile: $zipfile" +zip "$zipfile" $files + +destination="$releaseFolder/$projectName" +echo "destination: $sshUserHost:$destination" +ssh $sshUserHost -p $sshPort mkdir -p "$destination" +scp -P "$sshPort" "$zipfile" "$sshUserHost:$destination" +if [ "$setCurrent" = true ]; then + target="$destination/$zipfile" + slink="$destination/current.zip" + echo "linking $slink -> $target" + ssh $sshUserHost -p $sshPort ln -sf "$target" "$slink" +fi