Created
November 19, 2021 14:16
-
-
Save major/c19dcdb8fc719ecab6b07811b46d6955 to your computer and use it in GitHub Desktop.
Screenshot uploads to Backblaze B2 with Cloudflare CDN caching
This file contains hidden or 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
#!/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