Skip to content
Snippets Groups Projects
Unverified Commit 17a4dc27 authored by Volkor The Barbarian Warrior's avatar Volkor The Barbarian Warrior
Browse files

Fix up variable names. Correct ShellCheck

Shellcheck was complaining about a bunch of errors, now it is not.
parent 242cba79
No related branches found
No related tags found
No related merge requests found
#!/bin/bash #!/bin/bash
# SUpload (Screenshot-Upload) # SUpload (Screenshot-Upload)
VERSION="1.0" version="1.1"
## Colours ## Colours
R='\033[0;31m' r='\033[0;31m'
NC='\033[0m' nc='\033[0m'
G='\033[0;32m'
## Default Configs ## Default Configs
## WARNING: Do not change these files here, change them in the config file ## WARNING: Do not change these files here, change them in the config file
SFW=false sfw=false
DEBUG=false debug=false
SSHOT="maim" sshot="maim"
FILE_FORMAT="date +%F-%T.png" file_format="date +%F-%T.png"
FILE_DIR="${HOME}/Pictures/screenshots" file_dir="${HOME}/Pictures/screenshots"
BROWSER=false browser=false
CLIPBOARD=true clipboard=true
NOTIFICATION=true notification=true
LOG=true log=true
LOG_FILE="${HOME}/.supload.log" log_file="${HOME}/.supload.log"
CURL_OPTIONS="--progress-bar" curl_options="--progress-bar"
## Read from user config if exists, else read from system-wide (just use inbuilt defaults if none) ## Read from user config if exists, else read from system-wide (just use inbuilt defaults if none)
### User config takes priority over system-wide ### User config takes priority over system-wide
CONFIG=$HOME/.config/supload/settings.conf config=$HOME/.config/supload/settings.conf
if [ -f "${CONFIG}" ] ; then if [ -f "${config}" ] ; then
source "${CONFIG}" source "${config}"
elif [ -f "/etc/supload.conf" ] ; then elif [ -f "/etc/supload.conf" ] ; then
source "/etc/supload.conf" source "/etc/supload.conf"
fi fi
## Check dependencies (in case of a bad installation) ## Check dependencies (in case of a bad installation)
type jq >/dev/null 2>&1 || { echo -e >&2 "${R}ERROR:${NC} I require jq but it's not installed. Aborting."; exit 1; } type jq >/dev/null 2>&1 || { echo -e >&2 "${r}ERROR:${nc} I require jq but it's not installed. Aborting."; exit 1; }
type curl >/dev/null 2>&1 || { echo -e >&2 "${R}ERROR:${NC} I require curl but it's not installed. Aborting."; exit 1; } type curl >/dev/null 2>&1 || { echo -e >&2 "${r}ERROR:${nc} I require curl but it's not installed. Aborting."; exit 1; }
usage() { usage() {
cat <<EOF cat <<EOF
...@@ -49,7 +48,7 @@ Options: ...@@ -49,7 +48,7 @@ Options:
-V Verbose -V Verbose
-v Shows current version of SUpload -v Shows current version of SUpload
Examples: https://git.thecum.zone/Volkor/SUpload Examples: https://git.volkor.me/Volkor/SUpload
EOF EOF
exit 0 exit 0
...@@ -57,51 +56,51 @@ exit 0 ...@@ -57,51 +56,51 @@ exit 0
## Actual file uploading ## Actual file uploading
upload_file() { upload_file() {
if [[ "$SFW" = "true" ]] ; then if [[ "$sfw" = "true" ]] ; then
BASE_URL="https://volkor.me/" base_url="https://volkor.me/"
else else
BASE_URL="https://thecum.zone/" base_url="https://thecum.zone/"
fi fi
$DEBUG && echo -e "${R}DEBUG:${NC} BASE_URL: $BASE_URL" $debug && echo -e "${r}DEBUG:${nc} BASE_URL: $base_url"
## Upload to server ## Upload to server
echo "Uploading File: ("$1")" echo "Uploading File: ($1)"
response=$(curl $CURL_OPTIONS -F file=@"$1" "$BASE_URL") || { echo -e >&2 "${R}ERROR:${NC} Curl upload failure. (Invalid file, or bad internet connection)"; exit 1; } response=$(curl $curl_options -F file=@"$1" "$base_url") || { echo -e >&2 "${r}ERROR:${nc} Curl upload failure. (Invalid file, or bad internet connection)"; exit 1; }
$DEBUG && echo -e "${R}DEBUG:${NC} RESPONSE: $response" $debug && echo -e "${r}DEBUG:${nc} RESPONSE: $response"
url=$(echo $response | jq -r '.["url"]') url=$(echo "$response" | jq -r '.["url"]')
deletionlink=$(echo $response | jq -r '.["deletionurl"]') deletionlink=$(echo "$response" | jq -r '.["deletionurl"]')
$DEBUG && echo -e "${R}DEBUG:${NC} URL: $url" $debug && echo -e "${r}DEBUG:${nc} URL: $url"
## Browser, clipboard and logging. ## Browser, clipboard and logging.
if [ "$BROWSER" = "true" ] ; then if [ "$browser" = "true" ] ; then
echo "Opening browser" echo "Opening browser"
hash xdg-open && xdg-open $url &>/dev/null || echo "${R}ERROR:${NC} xdg-open was not found, or failed to run." hash xdg-open && xdg-open "$url" &>/dev/null || echo "${r}ERROR:${nc} xdg-open was not found, or failed to run."
fi fi
if [ "$CLIPBOARD" = "true" ] && [ -x "$(command -v xclip)" ]; then if [ "$clipboard" = "true" ] && [ -x "$(command -v xclip)" ]; then
echo ${url} | tr -d '\n' | xclip -selection clipboard ; echo "Copied URL to clipboard"; echo "${url}" | tr -d '\n' | xclip -selection clipboard ; echo "Copied URL to clipboard";
fi fi
$DEBUG && echo -e "${R}DEBUG:${NC} BROWSER: $BROWSER" $debug && echo -e "${r}DEBUG:${nc} BROWSER: $browser"
$DEBUG && echo -e "${R}DEBUG:${NC} CLIPBOARD: $CLIPBOARD" $debug && echo -e "${r}DEBUG:${nc} CLIPBOARD: $clipboard"
if [ -f "${LOG_FILE}" ]; then if [ -f "${log_file}" ]; then
if [ "$LOG" = "true" ]; then if [ "$log" = "true" ]; then
echo -n $(date +"[%Y-%m-%d %H:%M:%S]") >> $LOG_FILE && echo " Upload Response: $response" >> $LOG_FILE echo -n "$(date +"[%Y-%m-%d %H:%M:%S]")" >> "$log_file" && echo " Upload Response: $response" >> "$log_file"
fi fi
else else
touch $LOG_FILE touch "$log_file"
fi fi
$DEBUG && echo -e "${R}DEBUG:${NC} LOG: $LOG" $debug && echo -e "${r}DEBUG:${nc} LOG: $log"
$DEBUG && echo -e "${R}DEBUG:${NC} LOG_FILE: $LOG_FILE" $debug && echo -e "${r}DEBUG:${nc} LOG_FILE: $log_file"
upload_finished upload_finished
} }
upload_finished() { upload_finished() {
echo "URL: "${url} echo "URL: ${url}"
echo "Deletion URL: "${deletionlink} echo "Deletion URL: ${deletionlink}"
if [ "$NOTIFICATION" = "true" ] ; then if [ "$notification" = "true" ] ; then
notify-send "File uploaded." "URL: "${url} & exit 0 notify-send "File uploaded." "URL: ${url}" & exit 0
fi fi
exit 0 exit 0
} }
...@@ -109,58 +108,59 @@ upload_finished() { ...@@ -109,58 +108,59 @@ upload_finished() {
while getopts "fhosvV" opt; do while getopts "fhosvV" opt; do
case $opt in case $opt in
f) f)
SFW=true sfw=true
;; ;;
h) h)
usage usage
;; ;;
o) o)
BROWSER=true browser=true
;; ;;
s) s)
SCREENSHOT=true screenshot=true
;; ;;
V) V)
DEBUG=true debug=true
;; ;;
v) v)
echo "SUpload Version: "$VERSION echo "SUpload Version: "$version
exit 0 exit 0
;; ;;
*)
echo -e "${r}ERROR:${nc} Invalid Option."
esac esac
done done
FILE="${@:$OPTIND}" file="${*:$OPTIND}"
$DEBUG && echo -e "${R}DEBUG:${NC} OPTIONS: $@" $debug && echo -e "${r}DEBUG:${nc} OPTIONS: $*"
if [ "$SCREENSHOT" = "true" ] ; then if [ "$screenshot" = "true" ] ; then
echo "Click and hold to select screenshot area or click for window." echo "Click and hold to select screenshot area or click for window."
SCREEN_PATH="$FILE_DIR/`$FILE_FORMAT`" screen_path="$file_dir/$($file_format)"
$DEBUG && echo -e "${R}DEBUG:${NC} SCREEN_PATH: $SCREEN_PATH" $debug && echo -e "${r}DEBUG:${nc} SCREEN_PATH: $screen_path"
case $SSHOT in case $sshot in
maim) maim)
SCREEN_PROG="maim -s -o" ;; screen_prog="maim -s -o" ;;
scrot) scrot)
SCREEN_PROG="scrot -s" ;; screen_prog="scrot -s" ;;
*) *)
echo -e "${R}ERROR:${NC} Invalid SSHOT in config, must be scrot or maim." echo -e "${r}ERROR:${nc} Invalid SSHOT in config, must be scrot or maim."
exit 1 exit 1
;; ;;
esac esac
$DEBUG && echo -e "${R}DEBUG:${NC} SSHOT: $SSHOT" $debug && echo -e "${r}DEBUG:${nc} SSHOT: $sshot"
$($SCREEN_PROG ${SCREEN_PATH}) #> /dev/null 2>&1 if ! $screen_prog "${screen_path}"; then
if [ "${?}" != "0" ]; then echo -e "${r}ERROR:${nc} Failed to take screenshot (maim crashed/user exited)"
echo -e "${R}ERROR:${NC} Failed to take screenshot (User exited maim)"
exit 1 exit 1
fi fi
upload_file ${SCREEN_PATH} upload_file "${screen_path}"
fi fi
if [ "$1" = "" ] ; then if [ "$1" = "" ] ; then
echo -e "${R}ERROR:${NC} You must supply either STDIN (-) or a file!" echo -e "${r}ERROR:${nc} You must supply either STDIN (-) or a file!"
exit 1 exit 1
fi fi
upload_file "$FILE" upload_file "$file"
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment