-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote-build.sh
58 lines (50 loc) · 1.17 KB
/
remote-build.sh
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
50
51
52
53
54
55
56
57
58
#!/bin/bash
# check that the script is running from the project dir
if [[ ! -f $PWD/remote-build.sh ]]; then
echo "No remote-build.sh in current dir."
exit 1
fi
# check for host in the '.buildhost' file
BUILD_HOST=$(cat .buildhost 2>/dev/null)
if [ -z $BUILD_HOST ]; then
echo "Host not specified"
exit 1
fi
# split host into three parts:
# - optional 'rsync://'
# - mandatory host or IP or alias from .ssh/config
# - optional SSH port
IFS=":"
read a b c <<< "$BUILD_HOST"
if [[ -n $c ]]; then
HOST=${b##*/}
PORT=$c
elif [[ -n $b ]]; then
if [[ $b =~ ^[0-9]+$ ]]; then
PORT=$b
HOST=$a
else
HOST=${b##*/}
fi
elif [[ -n $a ]]; then
HOST=$a
else
echo "Unable to parse host"
exit 1
fi
if [[ -n $PORT ]]; then
PORT="-p$PORT"
fi
# save build arguments to '.buildargs' file
ARGS="$@"
if [ -z $ARGS ]; then
ARGS=$(cat .buildargs 2>/dev/null)
else
echo "$ARGS" >> .buildargs
fi
PROJECT=${PWD##*/}
BUILD_DIR=build/$PROJECT
BUILD_CMD="./build.sh"
# rsync to the build server and build
rsync -avr --exclude='tags' --exclude='remote-build.sh' . "$BUILD_HOST":"$BUILD_DIR"
ssh $PORT $HOST "cd $BUILD_DIR; $BUILD_CMD $ARGS"