#!/bin/sh # # s3curl needs Digest::HMAC. To install, run: # $ sudo perl -MCPAN -e shell # > install Digest::HMAC # # More information: # http://docs.amazonwebservices.com/AmazonS3/latest/index.html?LoggingHowTo.html if [ -z "${1}" ]; then echo "Usage: $(basename ${0}) logged_bucket [bucket_for_logs]" exit 1 fi SRC="${1}" test -n "${2}" && DST="${2}" || DST="${1}" echo "Access to files inside s3://${SRC} will be logged in s3://${DST}/s3-logs/${SRC}/." ID="personal" LANG=en_US.UTF-8 TMP=$(mktemp) # 1. Enable writing to the target bucket. echo "** reading acl for ${DST}" s3curl.pl --id ${ID} -- -s "http://${DST}.s3.amazonaws.com/?acl" | sed -e 's@@http://acs.amazonaws.com/groups/s3/LogDeliveryWRITEhttp://acs.amazonaws.com/groups/s3/LogDeliveryREAD_ACP@g' > "${TMP}" if [ -n "${EDITOR}" ]; then echo "** have a editor, letting you review acl" if [ -n "$(which tidy)" ]; then tidy -utf8 -xml -w 1024 -i -c -q -asxml -m ${TMP} fi vim ${TMP} fi echo "** updating acl for ${DST}" s3curl.pl --id ${ID} --put ${TMP} -- -s "http://${DST}.s3.amazonaws.com/?acl" # 2. Enable logging the source bucket. cat > $TMP << END ${DST} logs/${SRC}/access_log- END echo "** enabling logging for ${SRC}" s3curl.pl --id ${ID} --put ${TMP} -- -s "http://${SRC}.s3.amazonaws.com/?logging" rm -f ${TMP}