Created
October 30, 2015 20:08
-
-
Save drscream/b25024ed508da3507107 to your computer and use it in GitHub Desktop.
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 | |
# | |
# SaU : Screenshot and Upload | |
# Bash-Client Version: 0.11 | |
# (c) by DrScream, Wiedi | |
# this is free software, take what you need | |
# NOTE: | |
# requirements: | |
# - import (imagemagick) OR scrot OR screencapture | |
# - curl | |
# | |
#### FUNCTIONS #### | |
check() { | |
if [ $? ]; then | |
if [ "$2" != "silent" ];then | |
out 2 "$1 \t\t\t [ DONE ]" | |
fi | |
else | |
out 3 "Error: $1 failed!" | |
exit | |
fi | |
} | |
# $1 = [Welcome=0|Notice=1|Spam=2|Error=3] | |
# $2 = Message | |
out() { | |
case "$MODUS" in | |
0) echo -e $2;; | |
1) | |
case "$1" in | |
0 | 3) echo -e "\033[1;31m" $2 "\033[0m";; | |
1 | 2) echo -e "\033[1;32m" $2 "\033[0m";; | |
*) echo "eh?" && exit;; | |
esac | |
;; | |
2) | |
if [[ "$1" -eq 1 || "$1" -eq 3 ]]; then | |
xmessage "$2" | |
fi | |
;; | |
3) | |
if [ "$1" -eq 1 ]; then | |
kdialog --msgbox "$2" | |
elif [ "$1" -eq 3 ]; then | |
kdialog --error "$2" | |
fi | |
;; | |
4) | |
if [ "$1" -eq 1 ]; then | |
zenity --info --text "$2" | |
elif [ "$1" -eq 3 ]; then | |
zenity --error --text "$2" | |
fi | |
;; | |
*) echo "eh?" && exit;; | |
esac | |
} | |
#### "installer" #### | |
if [ -f ~/.frubar/sau.rc ]; then | |
source ~/.frubar/sau.rc | |
else | |
echo "This is the first time you're running SaU, congratulations" | |
echo "I'm creating a directory ~/.frubar/ for you now." | |
echo "To edit your settings you may want to edit ~/.frubar/sau.rc" | |
echo "Press Enter to proceed or CTRL+C to abort" | |
read | |
mkdir -p ~/.frubar | |
cat > ~/.frubar/sau.rc <<EOF | |
# This is your fresh SaU (Screenshot and Upload) Config File | |
# We use default settings here, you probably want to change them... | |
# default filename of the screenshot in your temp folder | |
FILENAME="\`date +%y%m%d-%H%M%S\`.jpg" | |
# username for the sau website, default is \`whoami\` | |
USERNAME="" | |
# program to create the screenshot | |
# 0=import (default) | |
# 1=scrot | |
# 2=screencapture | |
STOOL=0 | |
# if you want to keep your screenshots, uncomment the next line | |
#DONTDELETE=1 | |
# where to save the shots | |
TMPPATH=/tmp | |
# the logfile | |
LOGFILE=~/.frubar/sau.log | |
# enable loggin? 1=yes 0=no | |
LOGGING=1 | |
# This is probably what your looking for: the output modus | |
# here we have: | |
# 0=text console modus | |
# 1=text console modus with groovy colors | |
# 2=fast but ugly xmessage modus (requires xmessage) | |
# 3=funky kde style (requires kdialog) | |
# 4=gnome style (requires zenity) | |
MODUS=1 | |
# SaU can open your browser with the taken screenshot, | |
# you can define your browser of choice here | |
# if you have firefox prior to 1.5 uncomment the next line: | |
#BROWSER="firefox -remote openURL(%s,new-tab)" | |
# to disable this feature uncomment the next line: | |
#BROWSER="" | |
BROWSER="firefox %s" | |
# Image Quality can be defined here between 1 and 100 | |
# higher means better image quality but more data to upload | |
QUALITY=95 | |
# SaU can copy the url to your screenshot into your clipboard | |
# This requires xsel, which you can get from: | |
# http://www.niksula.cs.hut.fi/~vherva/xsel/ | |
# to enable this option set it to 1 (1=yes 0=no) | |
PASTE=0 | |
# congratulations, you're at the end of this config file :) | |
# if it doesn't work for you, you find some bug or just love that | |
# software don't hesitate to drop us a mail at [email protected] | |
EOF | |
source ~/.frubar/sau.rc | |
fi | |
#### CODE #### | |
out 0 "SaU : Screenshot and Upload | (c) DrScream, Wiedi" | |
out 0 "#################################################" | |
# requirements met? | |
if [ "$MODUS" -eq 2 ];then | |
which xmessage > /dev/null 2>&1 | |
if [ ! $? ]; then | |
MODUS=1 | |
out 3 "xmessage not found, falling back to MODUS=1" | |
fi | |
fi | |
if [ "$MODUS" -eq 3 ];then | |
which kdialog > /dev/null 2>&1 | |
if [ ! $? ]; then | |
MODUS=1 | |
out 3 "kdialog not found, falling back to MODUS=1" | |
fi | |
fi | |
if [ "$MODUS" -eq 4 ];then | |
which zenity > /dev/null 2>&1 | |
if [ ! $? ]; then | |
MODUS=1 | |
out 3 "zenity not found, falling back to MODUS=1" | |
fi | |
fi | |
if [[ "$STOOL" -eq "0" || -z "$STOOL" ]]; then | |
which import > /dev/null 2>&1 | |
check "import not found" "silent" | |
elif [ "$STOOL" -eq "1" ]; then | |
which scrot > /dev/null 2>&1 | |
check "scrot not found" "silent" | |
elif [ "$STOOL" -eq "2" ]; then | |
which screencapture > /dev/null 2>&1 | |
check "screencapture not found" "silent" | |
fi | |
which curl > /dev/null 2>&1 | |
check "curl not found" "silent" | |
# Taking the Screenshot | |
if [[ "$STOOL" -eq "0" || -z "$STOOL" ]]; then | |
import -window root -pause 0 -quality $QUALITY $TMPPATH/$FILENAME | |
elif [ "$STOOL" -eq "1" ]; then | |
scrot -q $QUALITY $TMPPATH/$FILENAME | |
elif [ "$STOOL" -eq "2" ]; then | |
screencapture $TMPPATH/$FILENAME | |
fi | |
check "taking screenshot" | |
# Loging | |
if [ "$LOGGING" -eq "1" ]; then | |
echo "$(date +"%m.%d.%y - %H:%M:%S"): $(whoami)" >> $LOGFILE | |
fi | |
# send it to the host | |
if [[ -z "$USERNAME" ]]; then | |
USERNAME=`whoami` | |
fi | |
ID=$(curl -s -F userfile=@$TMPPATH/$FILENAME -F "shooter=$USERNAME" "http://sau.frubar.net/") | |
check "uploading screenshot" | |
URL="http://sau.frubar.net/$ID" | |
# remove the tmp file | |
if [[ "$DONTDELETE" != 1 || -z "$DONTDELETE" ]]; then | |
rm $TMPPATH/$FILENAME | |
check "removing temp file" | |
fi | |
# copy to clipboard | |
if [ "$PASTE" -eq 1 ]; then | |
which xsel > /dev/null 2>&1 | |
if [ $? ]; then | |
echo -n $URL | xsel -c | |
fi | |
fi | |
# opening browser | |
if [[ ! -z "$BROWSER" ]]; then | |
BROWSER=$(printf "$BROWSER" $URL) | |
$BROWSER | |
fi | |
out 1 "SaU did it well again! ;-)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment