commit a45e32a7a849d2d1d280be2965e083e3c3e6d828
parent 34f9783c66d292aa582da05c8432eb59bc871297
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 11 Sep 2019 21:17:03 +0200
Add --delete option
Diffstat:
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/.local/bin/upload b/.local/bin/upload
@@ -25,6 +25,8 @@ show_help() {
echo " without changing its width-to-height ratio"
echo " -s, --sharpen if an image, sharpen all FILES"
echo " -g, --get get previously uploaded FILES instead of uploading"
+ echo " -d, --delete delete previously uploaded FILES instead of uploading"
+ echo " --get and --delete can be used together"
echo "the optional operations are performed in the order listed above."
echo "${0##*/} requires imagemagick and rsync to be installed on the system."
}
@@ -94,7 +96,11 @@ upload_file() {
}
download_file() {
- curl -OL "https://$host/files_nonpub/$1"
+ curl --fail -OL "https://$host/files_nonpub/$1"
+}
+
+delete_file() {
+ ssh -p "$port" "$user"@"$host" "rm /var/www/html/files_nonpub/$1"
}
die() {
@@ -107,6 +113,7 @@ border=0
resize=0
sharpen=0
get=0
+delete=0
while :; do
case "$1" in
-h|-\?|--help)
@@ -132,6 +139,9 @@ while :; do
-g|--get)
get=1
;;
+ -d|--delete)
+ delete=1
+ ;;
--) # end all options
shift
break
@@ -149,11 +159,18 @@ if [ $# -lt 1 ]; then
show_help
exit 1
fi
-
-if [ "$get" = 1 ]; then
- for f in "$@"; do
- download_file "$(basename "$f")"
- done
+
+if [ "$get" = 1 ] || [ "$delete" = 1 ]; then
+ if [ "$get" = 1 ]; then
+ for f in "$@"; do
+ download_file "$(basename "$f")"
+ done
+ fi
+ if [ "$delete" = 1 ]; then
+ for f in "$@"; do
+ delete_file "$(basename "$f")"
+ done
+ fi
else
if [ ! -f "$1" ]; then
msg="$(cat)"