dotwryn/bin/aws/s3/sync-media

59 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-09-24 15:36:29 +00:00
#!/bin/zsh
source "$HOME/.config/wryn/env/env.zsh"
source $ZSH_COLOR_UTIL
#####################################################################
case $1 in
pull ) PULL=1 ;;
push ) PUSH=1 ;;
esac
2021-09-25 06:06:44 +00:00
case $2 in
nodelete ) NODELETE=1 ;; # whether or not to pass '--delete' to s3 sync
# default is --delete
esac
2021-09-24 15:36:29 +00:00
[ ! $PULL ] && [ ! $PUSH ] && FATAL 'must specify "pull" or "push"'
#####################################################################
PULL_MEDIA() {
local TARGET="$1"
local REMOTE_TARGET="s3://$S3_SYNC_BUCKET/$1"
local LOCAL_TARGET="$HOME/$1"
[ ! -d $LOCAL_TARGET ] && mkdir -p $LOCAL_TARGET
2021-09-25 06:06:44 +00:00
local NO_DELETE="$2"
[ ! $NO_DELETE ] && FLAGS=--delete
2021-09-24 15:36:29 +00:00
CHECK "updating $1"
aws --profile $DOTWRYN_AWS_PROFILE \
s3 sync $REMOTE_TARGET $LOCAL_TARGET \
2021-09-25 06:06:44 +00:00
$FLAGS >/dev/null 2>&1 \
2021-09-24 15:36:29 +00:00
&& OK || WARN
}
PUSH_MEDIA() {
local TARGET="$1"
local REMOTE_TARGET="s3://$S3_SYNC_BUCKET/$1"
local LOCAL_TARGET="$HOME/$1"
2021-09-25 06:06:44 +00:00
local NO_DELETE="$2"
[ ! $NO_DELETE ] && FLAGS=--delete
2021-09-24 15:36:29 +00:00
CHECK "updating $1"
aws --profile $DOTWRYN_AWS_PROFILE \
s3 sync $LOCAL_TARGET $REMOTE_TARGET \
2021-09-25 06:06:44 +00:00
$FLAGS \
2021-09-24 15:36:29 +00:00
&& OK || WARN
}
for m in $S3_SYNC_MEDIA
do
2021-09-25 06:06:44 +00:00
[ $PULL ] && PULL_MEDIA $m $NODELETE
[ $PUSH ] && PUSH_MEDIA $m $NODELETE
2021-09-24 15:36:29 +00:00
done