-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·52 lines (45 loc) · 1.54 KB
/
run.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
#!/bin/sh
set -e
# host option
if [ -z "$WERCKER_RSYNC_NO_DELETE_HOST" ]
then
fail 'missing host option, please add this the rsync-deploy step in wercker.yml'
fi
# directory option
if [ -z "$WERCKER_RSYNC_NO_DELETE_DIRECTORY" ]
then
fail 'missing directory option, please add this the rsync-deploy step in wercker.yml'
fi
# user option
remote_user="ubuntu"
if [ -n "$WERCKER_RSYNC_NO_DELETE_USER" ]; # Check $WERCKER_BUNDLE_INSTALL exists and is not empty
then
remote_user="$WERCKER_RSYNC_NO_DELETE_USER"
fi
info "using user $remote_user"
# port option
remote_port="22"
if [ -n "$WERCKER_RSYNC_NO_DELETE_SSHPORT" ]; # Check $WERCKER_RSYNC_DEPLOY_SSHPORT exists and is not empty
then
remote_port="$WERCKER_RSYNC_NO_DELETE_SSHPORT"
fi
info "using remote port $remote_port"
# key option
rsync_command="ssh -o BatchMode=yes -p $remote_port" # Batchmode to prevent it from waiting on user input
if [ -n "$WERCKER_RSYNC_NO_DELETE_SSHKEY" ]
then
rsync_command="$rsync_command -i $WERCKER_RSYNC_NO_DELETE_SSHKEY"
fi
source_dir="./"
if [ -n "$WERCKER_RSYNC_NO_DELETE_SOURCE" ]; # check if source dir is specified
then
source_dir=$WERCKER_RSYNC_NO_DELETE_SOURCE
fi
info "Synchronizing $source_dir to $remote_user@$WERCKER_RSYNC_NO_DELETE_HOST:$WERCKER_RSYNC_NO_DELETE_DIRECTORY..."
sync_output=$(rsync -urltv --rsh="$rsync_command" "$source_dir" "$remote_user@$WERCKER_RSYNC_NO_DELETE_HOST:$WERCKER_RSYNC_NO_DELETE_DIRECTORY")
if [[ $? -ne 0 ]];then
warning $sync_output
fail 'rsync failed';
else
success "finished rsync synchronisation"
fi