aboutsummaryrefslogtreecommitdiff
path: root/gitdist
blob: 5054f4037846ca43f3afbca49a12d7a434915ff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env 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"
suffix=amd64Win (optional)'

source ./.gitdist || { echo "you need a .gitdist file in your git repo"; leave=true; }

if [ -z "$projectName" ] || [ -z "$sshUserHost" ] || [ -z "$sshPort" ] || [ -z "$releaseFolder" ] || [ -z "$files" ]; then
    echo "not all necessary variables provided - example of a .gitdist file:"
    echo
    echo "$example"
    leave=true
fi

if [ "$leave" = true ]; then
    exit 1
fi

timestamp=`date +"%Y%m%d-%H%M"`
currentBranch=`git rev-parse --abbrev-ref HEAD`

if [ "$currentBranch" = "master" ]; then
    zipfile="$projectName-$timestamp$suffix.zip"
    setCurrent=true
else
    zipfile="$projectName-$currentBranch-$timestamp$suffix.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