Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bryangarza/sour
base: 274494e1f0
...
head fork: bryangarza/sour
compare: 0fd5642ccb
  • 4 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 45 additions and 53 deletions.
  1. +45 −53 sour
View
98 sour
@@ -18,14 +18,12 @@ sour: usage:
EOF
}
-if [[ $1 == '-h' || $1 == '--help' || $1 == "-\?" ]]; then
+if [[ $1 == '-h' || $1 == '--help' || $1 == '-?' ]]; then
usage
exit 0
fi
function setDefaults {
- local self='setDefaults'
-
TMPDIR=${TMPDIR:-/tmp}
location=$(mktemp -d "$TMPDIR/XXXXXXXXXXXXXX") ||\
{ echo "ERROR could not create temporary directory" >&2; exit 1; }
@@ -33,7 +31,7 @@ function setDefaults {
logdestfile="$HOME/.sour/log/$(date +"%m-%d-%y").log"
keyfile="$HOME/.sour/key"
- datestamp=$(date +"%F_%H-%M-%S")
+ datestamp="$(date +"%F_%H-%M-%S")"
# For createNeededFiles
needed_files=("$logdestfile")
@@ -42,10 +40,10 @@ function setDefaults {
thumbcommand=''
selectioncommand=''
- forum=false
- keep=false
- download=false
- existing=false
+ forum=0
+ keep=0
+ download=0
+ existing=0
# this will be changed depending on if there is a download or use of an
# existing image
@@ -56,7 +54,7 @@ function setDefaults {
smallimageurl=''
smallimagedel=''
- firstdone=false
+ firstdone=0
}
# Files and directories needed for successful execution:
@@ -67,7 +65,6 @@ function setDefaults {
# Creating directories before populating with needed_files.
function createNeededFiles {
- local self='createNeededFiles'
for directory in "${needed_dirs[@]}"; do
if [[ ! -d "$directory" ]]; then
if ! mkdir "$directory" &> /dev/null; then
@@ -112,10 +109,10 @@ function moveTo {
}
function removeTemporaries {
- if [[ $keep == true ]]; then
- if [[ $existing == true ]]; then
+ if ((keep)); then
+ if ((existing)); then
- if [[ $forum == true ]]; then
+ if ((forum)); then
moveTo $smallimagelocation $working_dir
else
# If the if keep == true, existing == true, and forum ==
@@ -128,7 +125,7 @@ function removeTemporaries {
# existing == false, but we need to keep whatever images we have.
else
- if [[ $forum == true ]]; then
+ if ((forum)); then
moveTo $smallimagelocation $working_dir
fi
# Regardless of the thumbnail, we still need to move the regular
@@ -143,13 +140,11 @@ function removeTemporaries {
}
function setTraps {
- trap 'removeTemporaries' HUP QUIT
- trap 'removeTemporaries; trap - INT; kill -INT $$' INT
+ trap 'removeTemporaries' EXIT
}
function die {
echo -e "ERROR: $@\a" >&2
- removeTemporaries
echo '' | xclip
exit 1
}
@@ -158,7 +153,7 @@ function sendOutput {
echo "$datestamp: $largeimageurl $largeimagedel\
$smallimageurl $smallimagedel" >> "$logdestfile"
- if [[ $forum == true ]]; then
+ if ((forum)); then
echo "[url=$largeimageurl][img]$smallimageurl[/img][/url]"
else
# The prefix is equal to '' if it was not changed by the user.
@@ -171,48 +166,45 @@ function uploadFile {
}
function parseAndReturn {
- local resp=$(echo "$@" | sed '/encoding/d')
- local url=''
- local del=''
- local errorcheck$(echo "$response" | grep 'error')
-
- if [[ ! -z "$errorcheck" ]]; then
- die "errorcheck failed!"
+ local resp="$@"
+ if [[ $resp = *error* ]]; then
+ die "error found in response"
fi
- local url=$(echo "$resp" | sed -r 's/.*<original_image>(.*)<\/original_image>.*/\1/')
-
- local del=$(echo "$resp" | sed -r 's/.*<delete_page>(.*)<\/delete_page>.*/\1/')
+ url=${resp#*<original_image>}
+ url=${url%</original_image>*}
+
+ del=${resp#*<delete_page>}
+ del=${del%</delete_page>*}
- if [[ ${#url} -gt 45 || ${#url} -eq 0 ]]; then
- die "url too large or equal to zero"
- fi
+ # If correct, url will be length of 28
+ local url_length="${#url}"
+ (( url_length != 28)) && die "url too large or equal to zero"
- if [[ $firstdone == false ]]; then
- largeimageurl="$url"
- largeimagedel="$del"
- firstdone=true
- else
+ if ((firstdone)); then
smallimageurl="$url"
smallimagedel="$del"
+ else
+ largeimageurl="$url"
+ largeimagedel="$del"
+ firstdone=1
fi
}
function makeImageUpload {
- largeimageresponse=$(uploadFile $largeimagelocation)
+ largeimageresponse=$(uploadFile "$largeimagelocation")
parseAndReturn "$largeimageresponse"
checkAndMakeThumb
- removeTemporaries
}
function checkAndMakeThumb {
- if [[ $forum == true ]]; then
- if [[ $download == true || $existing == true ]]; then
- cp $largeimagelocation $smallimagelocation
- mogrify -path $location -resize 250x250 $smallimagelocation
+ if ((forum)); then
+ if ((download || existing)); then
+ cp "$largeimagelocation" "$smallimagelocation"
+ mogrify -path "$location" -resize 250x250 "$smallimagelocation"
fi
- smallimageresponse=$(uploadFile $smallimagelocation)
+ smallimageresponse=$(uploadFile "$smallimagelocation")
parseAndReturn "$smallimageresponse"
fi
}
@@ -223,11 +215,11 @@ function takeShot {
largeimagelocation="$location/$datestamp.$extension"
smallimagelocation="$location/$datestamp-thumb.$extension"
- if [[ $download == false && $existing == false ]]; then
- scrot $selectioncommand $largeimagelocation $thumbcommand
- elif [[ $download == true ]]; then
- curl $dl_source -o $largeimagelocation > /dev/null 2>&1
- elif [[ $existing == true ]]; then
+ if ! ((download || existing)); then
+ scrot $selectioncommand "$largeimagelocation" $thumbcommand
+ elif ((download)); then
+ curl "$dl_source" -o "$largeimagelocation" > /dev/null 2>&1
+ elif ((existing)); then
largeimagelocation="$ex_source"
fi
@@ -235,7 +227,7 @@ function takeShot {
}
function setExtension {
- extension=${1##*.}
+ extension="${1##*.}"
}
setDefaults
@@ -244,7 +236,7 @@ while :
do
case $1 in
-f | --forum)
- forum=true
+ forum=1
thumbcommand='--thumb 20'
shift
;;
@@ -253,17 +245,17 @@ do
shift
;;
-k | --keep)
- keep=true
+ keep=1
shift
;;
-u | --url)
- download=true
+ download=1
dl_source="$2"
setExtension "$dl_source"
shift 2
;;
-e | --existing)
- existing=true
+ existing=1
ex_source="$2"
setExtension "$ex_source"
shift 2

No commit comments for this range

Something went wrong with that request. Please try again.