73 lines
1.9 KiB
Bash
Executable File
73 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
BUCKET=johnmastodon.me
|
|
PROFILE="pacoAdmin"
|
|
NORMALAGE=300
|
|
# could be something like "foo" if everything is meant to be in /foo
|
|
PREFIX=""
|
|
AWS="aws --profile ${PROFILE} " # for simple debugging, change this to AWS="echo aws"
|
|
hugo
|
|
|
|
export AWS_DEFAULT_OUTPUT=text
|
|
export AWS_PAGER=
|
|
export AWS_REGION="us-east-2"
|
|
CACHE="--cache-control max-age=\"${NORMALAGE}\",public"
|
|
LONGSTUFF="css fonts img js"
|
|
LONGAGE=86400
|
|
EXCLUDE=""
|
|
export AWSLOG="/tmp/sync-log.txt"
|
|
|
|
for prefix in ${LONGSTUFF}
|
|
do
|
|
EXCLUDE="${EXCLUDE} --exclude 'public/${prefix}/*'"
|
|
done
|
|
|
|
rm -f ${AWSLOG}
|
|
${AWS} s3 sync --only-show-errors \
|
|
public s3://${BUCKET} --delete \
|
|
${EXCLUDE} \
|
|
${CACHE} 2>&1 >> ${AWSLOG}
|
|
|
|
# reset cache age for long assets
|
|
CACHE="--cache-control max-age=\"${LONGAGE}\",public"
|
|
|
|
for prefix in ${LONGSTUFF}
|
|
do
|
|
${AWS} s3 sync --only-show-errors \
|
|
"public/${prefix}" "s3://${BUCKET}/${prefix}" --delete \
|
|
${CACHE} 2>&1 >> ${AWSLOG}
|
|
done
|
|
|
|
# Robots.txt
|
|
${AWS} s3 \
|
|
cp public/robots.txt s3://${BUCKET}/robots.txt \
|
|
--content-type text/plain \
|
|
${CACHE} 2>&1 >> ${AWSLOG}
|
|
|
|
# back to normal for special files
|
|
CACHE="--cache-control max-age=\"${NORMALAGE}\",public"
|
|
|
|
# Handle some one-offs
|
|
|
|
${AWS} s3 \
|
|
cp public/sitemap.xml s3://${BUCKET}/sitemap.xml \
|
|
--content-type text/xml \
|
|
${CACHE} 2>&1 >> ${AWSLOG}
|
|
|
|
# back to normal for index files
|
|
CACHE="--cache-control max-age=\"${NORMALAGE}\",public"
|
|
|
|
echo "Writing index files to directory markers"
|
|
time (find public/* -name index.html | while read -r line; do
|
|
# ${AWS} s3 cp $line "s3://$BUCKET/${BASH_REMATCH[1]}"
|
|
# get rid of "public/"
|
|
OBJKEY=${line#public/*}
|
|
# get rid of "/index.html"
|
|
OBJKEY=${OBJKEY%/index.html}
|
|
echo "Uploading from $line to s3://${BUCKET}/${OBJKEY}/"
|
|
${AWS} s3api put-object --bucket "$BUCKET" \
|
|
--body ${line} --key "${OBJKEY}" --content-type text/html ${CACHE} 2>&1 >> ${AWSLOG}
|
|
${AWS} s3api put-object --bucket "$BUCKET" \
|
|
--body ${line} --key "${OBJKEY}/" --content-type text/html ${CACHE} 2>&1 >> ${AWSLOG}
|
|
done)
|