Skip to content

Instantly share code, notes, and snippets.

@andrewbuss
Created January 19, 2016 20:22
Show Gist options
  • Select an option

  • Save andrewbuss/fddbb24b65982e9f379e to your computer and use it in GitHub Desktop.

Select an option

Save andrewbuss/fddbb24b65982e9f379e to your computer and use it in GitHub Desktop.
#!/bin/bash
screenshot_dir=/home/andrew/screenshots/
screenshot_log=$screenshot_dir/screenshots.log
host=cryptarch.net
host_img_root=/var/www/html/img
host_img_urlbase=https://cryptarch.net/img/
img_file=${screenshot_dir}/$(date -Iseconds)
img_file+=.png
sleep 0.1
scrot -s "${img_file}"
# get the SHA256 hash of the image
img_hash=$(sha256sum $img_file | cut -f 1 -d " ")
# convert to base62
BASE62=($(echo {0..9} {a..z} {A..Z}))
read hash62_dec < <(bc <<< "obase=62; ibase=16; ${img_hash^^}")
hash62=
for i in $hash62_dec; do
hash62+=${BASE62[$(( 10#$i))]}
done
echo "${img_file} ${img_hash} ${host_img_urlbase}${hash62:0:5}.png" >> $screenshot_log
scp ${img_file} ${host}:${host_img_root}/${img_hash}.png
ssh ${host} ln -sfv ${host_img_root}/${img_hash}.png ${host_img_root}/${hash62:0:5}.png
echo "${host_img_urlbase}${hash62:0:5}.png"
xdg-open "${host_img_urlbase}${hash62:0:5}.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment