commit d4aace0f0eb47020e42a8b157318d60b6c82a8b7
parent fdb08566fc4d58abc432251e2348de6357451908
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Tue, 19 Mar 2019 21:11:22 +0100
Fix upload target and accept stdin
Diffstat:
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/links/bin/upload b/links/bin/upload
@@ -6,12 +6,13 @@ version=1.0
# Upload target
host="adamsgaard.dk"
user="ad"
-port="12344"
-remotedir="~/webroot/files_nonpub"
+port="12346"
+remotedir="/var/www/html/files_nonpub"
function show_help {
echo "usage: ${0##*/} [OPTIONS] FILE1 [FILE2...[FILE N]]"
echo "will upload each FILE to $user@$host:$remotedir"
+ echo "If no FILE is specified, this program will expect stdin."
echo "OPTIONS are one or more of the following:"
echo " -h, --help show this message"
echo " -v, --version show version and license information"
@@ -118,16 +119,22 @@ while :; do
shift
done
-[ $# -lt 1 ] && die 'Error: No input FILE[S] specified'
-# loop over FILE[S]
-for f in "$@"; do
+if [ $# -lt 1 ]; then
+ msg="$(cat)"
tempfile="$(mktemp)"
- [ ! -f "$f" ] && die "Error: $f is not a file"
- cp "$f" "$tempfile"
+ echo -e -n "$msg" > "$tempfile"
+ upload_file "$tempfile" "${tempfile##*.}"
+else
+ # loop over FILE[S]
+ for f in "$@"; do
+ tempfile="$(mktemp)"
+ [ ! -f "$f" ] && die "Error: $f is not a file"
+ cp "$f" "$tempfile"
- [ "$border" = 1 ] && add_border "$tempfile" "$f"
- [ "$resize" = 1 ] && add_resize "$tempfile" "$f"
- [ "$sharpen" = 1 ] && add_sharpening "$tempfile" "$f"
+ [ "$border" = 1 ] && add_border "$tempfile" "$f"
+ [ "$resize" = 1 ] && add_resize "$tempfile" "$f"
+ [ "$sharpen" = 1 ] && add_sharpening "$tempfile" "$f"
- upload_file "$tempfile" "$(basename "$f")"
-done
+ upload_file "$tempfile" "$(basename "$f")"
+ done
+fi