Skip to content

Instantly share code, notes, and snippets.

@major
Created November 19, 2021 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save major/c19dcdb8fc719ecab6b07811b46d6955 to your computer and use it in GitHub Desktop.
Save major/c19dcdb8fc719ecab6b07811b46d6955 to your computer and use it in GitHub Desktop.
Screenshot uploads to Backblaze B2 with Cloudflare CDN caching
#!/bin/bash
set -euxo pipefail
# Set up the local filename and path.
FILE_STRING=$(date +%s | sha256sum | cut -c1-8)
FILE_NAME="${FILE_STRING}.png"
SCREENSHOT_PATH="/home/major/Pictures/screenshots/${FILE_NAME}"
# Configure the B2/CDN details.
CDN_URL="https://cdn.major.io"
BUCKET_NAME=majors-static-files
PUBLIC_URL=${CDN_URL}/${FILE_NAME}
# Take a screenshot.
maim -B -s ${SCREENSHOT_PATH}
# Upload the screenshot to S3.
s3cmd put ${SCREENSHOT_PATH} s3://${BUCKET_NAME}
# Prime the CDN cache and verify the screenshot is there.
curl -o /tmp/${FILE_NAME} $PUBLIC_URL
# Send a notification and copy the URL to the clipboard for faster posting. 😜
notify-send -i ${SCREENSHOT_PATH} "Screenshot uploaded" $PUBLIC_URL
echo $PUBLIC_URL | xclip -sel clip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment