forked from koding/step-s3put
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
56 lines (48 loc) · 1.68 KB
/
run.sh
File metadata and controls
56 lines (48 loc) · 1.68 KB
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
#!/bin/sh
AWS_BIN="$WERCKER_ROOT/aws"
set -e
cd $HOME
if [ ! -n "$WERCKER_S3PUT_AWSCLI_FILE" ]
then
WERCKER_S3PUT_AWSCLI_FILE=$WERCKER_ROOT
fi
if [ ! -n "$WERCKER_S3PUT_AWSCLI_BUCKET" ]
then
fail 'missing or empty option bucket, please check wercker.yml'
fi
if ! type aws &> /dev/null ;
then
fail 'aws-cli not found, please run on a container with aws-cli installed'
fi
info 'starting s3 upload'
set +e
if [ -d $WERCKER_S3PUT_AWSCLI_FILE ] ;
then
cd $WERCKER_S3PUT_AWSCLI_FILE
for file in $WERCKER_S3PUT_AWSCLI_FILE/* ; do
if [ -f $file ];
then
fname=$(basename $file)
debug "$AWS_BIN s3api put-object --bucket $WERCKER_S3PUT_AWSCLI_BUCKET --key $WERCKER_S3PUT_AWSCLI_KEY_PREFIX$fname --body $file $WERCKER_S3PUT_AWSCLI_OPTIONS"
sync_output=$($AWS_BIN s3api put-object --bucket $WERCKER_S3PUT_AWSCLI_BUCKET --key $WERCKER_S3PUT_AWSCLI_KEY_PREFIX$fname --body $file $WERCKER_S3PUT_AWSCLI_OPTIONS)
if [[ $? -ne 0 ]];then
debug $sync_output
fail 'aws-cli failed';
fi
fi
done
elif [ -f $WERCKER_S3PUT_AWSCLI_FILE ] ;
then
cd $WERCKER_ROOT
fname=$(basename $WERCKER_S3PUT_AWSCLI_FILE)
debug "$AWS_BIN s3api put-object --bucket $WERCKER_S3PUT_AWSCLI_BUCKET --key $WERCKER_S3PUT_AWSCLI_KEY_PREFIX$fname --body $WERCKER_S3PUT_AWSCLI_FILE $WERCKER_S3PUT_AWSCLI_OPTIONS"
sync_output=$($AWS_BIN s3api put-object --bucket $WERCKER_S3PUT_AWSCLI_BUCKET --key $WERCKER_S3PUT_AWSCLI_KEY_PREFIX$fname --body $WERCKER_S3PUT_AWSCLI_FILE $WERCKER_S3PUT_AWSCLI_OPTIONS)
if [[ $? -ne 0 ]];then
debug $sync_output
fail 'aws-cli failed';
fi
else
fail "file or folder $WERCKER_S3PUT_AWSCLI_FILE not found"
fi
success 'finished s3 upload';
set -e