BUCKET=download.longaccess.com
REGION=us-east-1
AWS_ACCESS_KEY_ID="AKIAIYFVJE5NMMFOGYMQ"
AWS_SECRET_ACCESS_KEY="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"

cmd=$(which s3put 2>/dev/null) ||
    cmd=$(which s3cmd 2>/dev/null)

case $cmd in
*s3put) 
    export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
    s3put -g public-read --bucket $BUCKET --region $REGION --prefix $PWD $1
    ;;
*s3cmd)
    s3cmd put -P $@ s3://${BUCKET}
    ;;
*) 
    echo "upload command not found."
    exit 1
esac

if [ -n "$2" ] ; then
    export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
    python - <<EOF
from boto.s3.connection import S3Connection
key = S3Connection().get_bucket("$BUCKET").new_key("$2")
key.set_redirect("http://$BUCKET/$1")
key.set_acl('public-read')
EOF
fi
