forked from icio/step-s3sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·73 lines (57 loc) · 1.82 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
sudo pip install -r $WERCKER_STEP_ROOT/requirements.txt
set_auth() {
local s3cnf="$HOME/.s3cfg"
if [ -e "$s3cnf" ]; then
warn '.s3cfg file already exists in home directory and will be overwritten'
fi
echo '[default]' > "$s3cnf"
echo "access_key=$WERCKER_S3SYNC_KEY_ID" >> "$s3cnf"
echo "secret_key=$WERCKER_S3SYNC_KEY_SECRET" >> "$s3cnf"
debug "generated .s3cfg for key $WERCKER_S3SYNC_KEY_ID"
}
main() {
set_auth
info 'starting s3 synchronisation'
if [ ! -n "$WERCKER_S3SYNC_KEY_ID" ]; then
fail 'missing or empty option key_id, please check wercker.yml'
fi
if [ ! -n "$WERCKER_S3SYNC_KEY_SECRET" ]; then
fail 'missing or empty option key_secret, please check wercker.yml'
fi
if [ ! -n "$WERCKER_S3SYNC_BUCKET_URL" ]; then
fail 'missing or empty option bucket_url, please check wercker.yml'
fi
if [ ! -n "$WERCKER_S3SYNC_OPTS" ]; then
export WERCKER_S3SYNC_OPTS="--acl-public"
fi
if [ -n "$WERCKER_S3SYNC_DELETE_REMOVED" ]; then
if [ "$WERCKER_S3SYNC_DELETE_REMOVED" = "true" ]; then
export WERCKER_S3SYNC_DELETE_REMOVED="--delete-removed"
else
unset WERCKER_S3SYNC_DELETE_REMOVED
fi
else
export WERCKER_S3SYNC_DELETE_REMOVED="--delete-removed"
fi
source_dir="$WERCKER_ROOT/$WERCKER_S3SYNC_SOURCE_DIR"
if cd "$source_dir";
then
debug "changed directory $source_dir, content is: $(ls -l)"
else
fail "unable to change directory to $source_dir"
fi
set +e
local SYNC="$WERCKER_STEP_ROOT/s3cmd sync $WERCKER_S3SYNC_OPTS $WERCKER_S3SYNC_DELETE_REMOVED --verbose ./ $WERCKER_S3SYNC_BUCKET_URL"
debug "$SYNC"
local sync_output=$($SYNC)
if [[ $? -ne 0 ]];then
echo "$sync_output"
fail 's3cmd failed';
else
echo "$sync_output"
success 'finished s3 synchronisation';
fi
set -e
}
main