Skip to content

Instantly share code, notes, and snippets.

@dotStart
Last active October 5, 2015 06:12
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dotStart/7aa2ec4a2396b503cbac to your computer and use it in GitHub Desktop.
Provides a simple Amazon S3 screenshot tool.
#!/bin/bash
#----------
# Akkarin's Simple S3 Screenshot Script
#
# Requirements:
# - shutter
# - awscli
# - zenity
#
# Note: The directory defined in $SCREENSHOT_PATH needs to exist!
#
#################
# Configuration #
#################
AWS_S3_BUCKET="bucket-name"
AWS_S3_PATH=""
# Permissions can be set to private, public-read, public-read-write, authenticated-read, bucket-owner-read, bucket-owner-full-control and log-delivery-write
AWS_S3_PERMISSIONS="public-read"
AWS_REGION="eu-west-1"
SCREENSHOT_PATH="/home/username/Pictures/Screenshots/"
SCREENSHOT_URL="http://bucket-url/%s"
########################
# END OF CONFIGURATION #
########################
echo "Uploading to ${AWS_S3_BUCKET}/${AWS_S3_PATH}"
# Generate a filename
DATE=$(date +%H%M%S%j%y)
RNDNAME=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w 10 | head -n 1)
FILENAME="${DATE}-${RNDNAME}.png"
FILE_PATH="${SCREENSHOT_PATH}${FILENAME}"
# Log
echo "Writing Screenshot to ${FILE_PATH}"
# Take screenshot
shutter -n -c -s -o ${FILE_PATH} -e
# Upload
if [ -f ${FILE_PATH} ]; then
echo "Uploading ..."
aws s3 cp --region ${AWS_REGION} --acl ${AWS_S3_PERMISSIONS} ${FILE_PATH} s3://${AWS_S3_BUCKET}/${AWS_S3_PATH}
# Add to clipboard
printf "${SCREENSHOT_URL}" "${FILENAME}" | xclip -sel clip
# Notify user
zenity --notification --text="Upload finished successfully!"
sleep 1s
# Get rekt zenity!
kill $!
else
echo "Upload aborted! No file written!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment