Last active
September 16, 2015 13:24
-
-
Save lokulin/5b5e4c43f79f2b638ee2 to your computer and use it in GitHub Desktop.
Ghetto Dropbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
exec 1> >(logger -s -t $(basename $0)) 2>&1 | |
WATCH_DIR="/cache/" | |
S3_BUCKET="com.lauchlin.cache" | |
AWS_REGION="ap-southeast-2" | |
aws s3 sync --delete "${WATCH_DIR}" "s3://${S3_BUCKET}${WATCH_DIR}" \ | |
--region ap-southeast-2 | |
inotifywait -mr -e moved_to,close_write,moved_from,delete \ | |
--format "%e %w%f" $WATCH_DIR | while read FILE; do | |
echo $FILE | |
event="${FILE/ *}" | |
file="${FILE/$event }" | |
event_command="${event/,*}" | |
dir="${event/$event_command,}" | |
if [[ "${event_command}" == "MOVED_FROM" || "${event_command}" == "DELETE" ]]; then | |
if [[ "${dir}" == "ISDIR" ]]; then | |
aws s3 rm "s3://${S3_BUCKET}${file}/" \ | |
--recursive \ | |
--region $AWS_REGION | |
else | |
aws s3 rm "s3://${S3_BUCKET}${file}" \ | |
--region $AWS_REGION | |
fi | |
else | |
if [[ "${dir}" == "ISDIR" ]]; then | |
aws s3 cp "${file}" "s3://${S3_BUCKET}${file}" \ | |
--recursive \ | |
--region $AWS_REGION | |
else | |
aws s3 cp "${file}" "s3://${S3_BUCKET}${file}" \ | |
--region $AWS_REGION | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment