Created
April 6, 2018 12:08
-
-
Save icyphox/ee5035135879e455fb7063f363ddd5ee to your computer and use it in GitHub Desktop.
scrotup.sh
This file contains 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 | |
red="\e[31m" | |
grn="\e[32m" | |
ylw="\e[33m" | |
cyn="\e[36m" | |
blu="\e[34m" | |
prp="\e[35m" | |
bprp="\e[35;1m" | |
rst="\e[0m" | |
# path to save screenshots and logs | |
save_dir="$HOME/scrots" | |
# application to open when lien is called | |
# with the -e tag | |
editor_app="gimp" | |
upload() { | |
if [ ! -z $hosts ] | |
then | |
case $fhost in | |
t|teknik) | |
uptek $1 | |
;; | |
0|0x0) | |
upoxo $1 | |
;; | |
i|icy) | |
upicy $1 | |
;; | |
n|transfer) | |
uptransfer $1 | |
;; | |
esac | |
else | |
echo "You need to specify a file host." | |
fi | |
} | |
uptek() { | |
local iext="${1##*.}" | |
if [[ "${iext}" == "png" || "${iext}" == "PNG" ]]; then | |
out=$( curl -sf -F "contentType=image/png" -F "encrypt=${encrypt}" -F file="@${1}" https://api.teknik.io/v1/Upload ) | |
else | |
out=$( curl -sf -F "encrypt=${encrypt}" -F file="@${1}" https://api.teknik.io/v1/Upload ) | |
fi | |
if [[ "${out}" =~ "error" ]] | |
then | |
echo -e "$red Error $rst" | |
notify-send "Failed to upload ${1}" | |
exit 1 | |
else | |
id="${out##*Name\":\"}" | |
id="${id%%\"*}" | |
echo "https://u.teknik.io/${id}" | |
local file_path=$( readlink -f $save_dir/$1 ) | |
echo "${file_path} - https://u.teknik.io/${id}" >> $save_dir/lien_logs | |
notify-send "Uploaded" "${1} to teknik.io" | |
copy https://u.teknik.io/${id} | |
fi | |
} | |
uptransfer() { | |
local id=$( curl -s --upload-file $1 https://transfer.sh/$1 ) | |
if [[ -z "${id// }" ]] | |
then | |
echo -e "${red}Error $rst" | |
notify-send "Failed to upload ${1}" | |
exit 1 | |
else | |
echo "${id}" | |
local file_path=$( readlink -f $save_dir/$1 ) | |
echo "${file_path} - ${id}" >> $save_dir/lien_logs | |
notify-send "Uploaded" "${1} to 0x0.st" | |
copy $id | |
fi | |
} | |
upoxo() { | |
local id=$( curl -sf -F "file=@${1}" https://0x0.st ) | |
if [[ -z "${id// }" ]] | |
then | |
echo -e "${red}Error $rst" | |
notify-send "Failed to upload ${1}" | |
exit 1 | |
else | |
echo "${id}" | |
local file_path=$( readlink -f $save_dir/$1 ) | |
echo "${file_path} - ${id}" >> $save_dir/lien_logs | |
notify-send "Uploaded" "${1} to 0x0.st" | |
copy $id | |
fi | |
} | |
upicy() { | |
local id=$( scp ${1} boop:www/upload/ ) | |
if [[ -z "${id// }" ]] | |
then | |
echo -e "${red} Error $rst" | |
notify-send "Failed to upload ${1}" | |
exit 1 | |
else | |
echo "${id}" | |
local file_path=$( readlink -f $1 ) | |
echo "${file_path} - ${id}" >> $save_dir/lien_logs | |
notify-send "Uploaded" "${1} to xix.ph0x.me" | |
copy $id | |
fi | |
} | |
copy() { | |
echo $1 | xclip -selection clipboard | |
} | |
print_logs() { | |
if [ ! -f $save_dir/lien_logs ] | |
then | |
echo -e "${red}No logs${rst}" | |
else | |
tac $save_dir/lien_logs | |
fi | |
} | |
clear_logs() { | |
if [ ! -f $save_dir/lien_logs ] | |
then | |
echo -e "${red}No logs${rst}" | |
else | |
rm -f $save_dir/lien_logs | |
echo "Logs cleared." | |
fi | |
} | |
print_help(){ | |
echo -e "${grn}Usage:${rst}" | |
echo "lien [options] [file]" | |
echo | |
echo "-h Display this help message and exit. Does not require a [file]." | |
echo "-f Upload a file to a file host." | |
echo " The available hosts are:" | |
echo " 0x0.st (0/0x0)" | |
echo " teknik.io (t/teknik)" | |
echo " xix.ph0x.me (i/icy) [requires an ssh key]" | |
echo " transfer.sh (n)" | |
echo "-s Take an interactive screenshot." | |
echo "-u Take a screenshot of the focused window." | |
echo "-a Take a screenshot of the entire viewport." | |
echo "-l Print logs of previous uploads. Logs are stored at $save_dir." | |
echo "-c Clear all logs." | |
echo | |
echo -e "${grn}Examples:${rst}" | |
echo | |
echo "# Upload a text file to teknik" | |
echo "lien -f teknik plain.txt" | |
echo | |
echo "# Take a selective screenshot" | |
echo "lien -s shot.png" | |
echo | |
echo "# Take a screenshot of the focused window, and upload it to 0x0.st" | |
echo "lien -uf 0x0 focus.png" | |
} | |
method=0 | |
hosts=0 | |
delay=0 | |
edit=0 | |
while getopts :chlusaef:d: options | |
do | |
case $options in | |
u) | |
method=1 | |
;; | |
s) | |
method=2 | |
;; | |
a) | |
method=3 | |
;; | |
f) | |
hosts=1 | |
fhost="$OPTARG" | |
;; | |
d) | |
delay="$OPTARG" | |
;; | |
l) | |
print_logs | |
;; | |
c) | |
clear_logs | |
;; | |
h|?) | |
print_help | |
;; | |
*) | |
print_help | |
;; | |
esac | |
done | |
shift $(( $OPTIND -1 )) | |
if [ $# -gt 1 ] | |
then | |
echo "Too many arguments." | |
echo "Try lien -h for help." | |
exit 1 | |
elif [ $# -lt 0 ] | |
then | |
echo "Too few arguments." | |
echo "Try lien -h for help." | |
exit 1 | |
elif [ $# -eq 0 ] | |
then | |
fname=$( date +"%T-%d.%m.%y" ) | |
fname="$fname.png" | |
else | |
fname=$1 | |
fi | |
case $method in | |
1) | |
scrot -d $delay -u $fname | |
upload $fname | |
mv -f "$fname" "$save_dir/$fname" | |
exit 1 | |
;; | |
2) | |
scrot -d $delay -s $fname | |
upload $fname | |
mv -f "$fname" "$save_dir/$fname" | |
exit 1 | |
;; | |
3) | |
scrot -d $delay $fname | |
upload $fname | |
mv -f "$fname" "$save_dir/$fname" | |
exit 1 | |
;; | |
0) | |
upload $fname | |
exit 1 | |
;; | |
esac | |
exit 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment