2018-06-17 10:01:35 +02:00
|
|
|
#!/usr/bin/env bash
|
2018-06-09 18:26:09 +02:00
|
|
|
|
|
|
|
###################################
|
|
|
|
# gitdist packs zip archives and #
|
|
|
|
# copies them to a remote server #
|
|
|
|
###################################
|
|
|
|
|
|
|
|
example='projectName=spameggs
|
|
|
|
sshUserHost="foo@bar.org"
|
|
|
|
sshPort=22
|
|
|
|
releaseFolder=/srv/releases
|
2018-10-03 18:59:08 +02:00
|
|
|
files="binary1 binary2 readme.md"
|
|
|
|
suffix=amd64Win (optional)'
|
2018-06-09 18:26:09 +02:00
|
|
|
|
2018-12-23 17:53:32 +01:00
|
|
|
source ./.gitdist || { echo "you need a .gitdist file in your git repo"; leave=true; }
|
2018-06-09 18:26:09 +02:00
|
|
|
|
|
|
|
if [ -z "$projectName" ] || [ -z "$sshUserHost" ] || [ -z "$sshPort" ] || [ -z "$releaseFolder" ] || [ -z "$files" ]; then
|
2018-10-03 18:59:08 +02:00
|
|
|
echo "not all necessary variables provided - example of a .gitdist file:"
|
2018-06-09 18:26:09 +02:00
|
|
|
echo
|
|
|
|
echo "$example"
|
2018-10-03 18:59:08 +02:00
|
|
|
leave=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$leave" = true ]; then
|
2018-06-09 18:26:09 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-21 14:42:01 +02:00
|
|
|
timestamp=`date -u +"%F-%T"`
|
2018-06-09 18:26:09 +02:00
|
|
|
currentBranch=`git rev-parse --abbrev-ref HEAD`
|
|
|
|
|
|
|
|
if [ "$currentBranch" = "master" ]; then
|
2018-10-03 18:59:08 +02:00
|
|
|
zipfile="$projectName-$timestamp$suffix.zip"
|
2018-06-09 18:26:09 +02:00
|
|
|
setCurrent=true
|
|
|
|
else
|
2018-10-03 18:59:08 +02:00
|
|
|
zipfile="$projectName-$currentBranch-$timestamp$suffix.zip"
|
2018-06-09 18:26:09 +02:00
|
|
|
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
|