1+ #! /bin/sh
2+ set -e
3+ cd $HOME
4+ if [ ! -n " $WERCKER_S3PUT_KEY_ID " ]
5+ then
6+ fail ' missing or empty option key_id, please check wercker.yml'
7+ fi
8+
9+ if [ ! -n " $WERCKER_S3PUT_KEY_SECRET " ]
10+ then
11+ fail ' missing or empty option key_secret, please check wercker.yml'
12+ fi
13+
14+ if [ ! -n " $WERCKER_S3PUT_BUCKET_URL " ]
15+ then
16+ fail ' missing or empty option bucket_url, please check wercker.yml'
17+ fi
18+
19+ if [ ! -n " $WERCKER_S3PUT_SOURCE_FILE " ]
20+ then
21+ fail ' missing or empty option source_file, please check wercker.yml'
22+ fi
23+
24+ if [ ! -n " $WERCKER_S3PUT_DEST_FILE " ]
25+ then
26+ fail ' missing or empty option dest_file, please check wercker.yml'
27+ fi
28+
29+ if ! type s3cmd & > /dev/null ;
30+ then
31+ info ' s3cmd not found, start installing it'
32+ wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -
33+ sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
34+ sudo apt-get update && sudo apt-get install s3cmd
35+ success ' s3cmd installed succesfully'
36+ else
37+ info ' skip s3cmd install, command already available'
38+ debug " type s3cmd: $( type s3cmd) "
39+ fi
40+
41+ if [ -e ' .s3cfg' ]
42+ then
43+ warn ' .s3cfg file already exists in home directory and will be overwritten'
44+ fi
45+
46+ echo ' [default]' > ' .s3cfg'
47+ echo " access_key=$WERCKER_S3PUT_KEY_ID " >> .s3cfg
48+ echo " secret_key=$WERCKER_S3PUT_KEY_SECRET " >> .s3cfg
49+ debug " generated .s3cfg for key $WERCKER_S3PUT_KEY_ID "
50+
51+ source_file=" $WERCKER_ROOT /$WERCKER_S3PUT_SOURCE_FILE "
52+ dest_file=" $WERCKER_S3PUT_BUCKET_URL /$WERCKER_S3PUT_DEST_FILE "
53+
54+ info ' starting s3 upload'
55+
56+ # TODO make public an option
57+
58+ set +e
59+ debug " s3cmd put --acl-public --verbose '$source_file ' '$dest_file '"
60+ sync_output=$( s3cmd sync --acl-public --verbose " $source_file " " $dest_file " )
61+
62+ if [[ $? -ne 0 ]]; then
63+ warning $sync_output
64+ fail ' s3cmd failed' ;
65+ else
66+ success ' finished s3 upload' ;
67+ fi
68+ set -e
0 commit comments