summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-09-18 20:39:20 +0100
committerubq323 <ubq323@ubq323.website>2023-09-18 20:39:20 +0100
commit96a4d580a34a5670a9dc7285c8e0b591193ccf9b (patch)
tree0f43762d7158556d4c6741161cfbe4a84b130500 /bin
parent46596692dcbd30c8d105d79b96aacc8b9f3bd12f (diff)
various
Diffstat (limited to 'bin')
-rwxr-xr-xbin/rupload45
1 files changed, 33 insertions, 12 deletions
diff --git a/bin/rupload b/bin/rupload
index c414b68..74c943c 100755
--- a/bin/rupload
+++ b/bin/rupload
@@ -1,5 +1,9 @@
#!/bin/sh
+REMOTE="do"
+URLBASE="https://ubq323.website/files/"
+REMOTEDIR="/srv/web/ubq/files/"
+
if [ $# -eq 0 ]; then
printf '%s\n' "usage: $0 [-n] [-p] [-x EXT | -r NAME | -R] FILENAME" >&2
printf '\t%s\n' "-n: dry run (don't actually upload anything)" >&2
@@ -13,6 +17,7 @@ fi
dry_run=0
samename=0
printurl=0
+saved_stdin=0
override_rname=
while [ $# -gt 1 ]; do
if [ "$1" = "-x" ]; then
@@ -36,30 +41,43 @@ while [ $# -gt 1 ]; do
fi
done
-if [ ! -f "$1" ]; then
- printf %s "$1: file does not exist" >&2
+target="$1"
+
+if [ "$1" = "-" ]; then
+ tempfile="$(mktemp /tmp/tmp_XXXXXXXXXXX)"
+ # echo yeah "$tempfile"
+ cat >"$tempfile"
+ saved_stdin=1
+ target="$tempfile"
+fi
+
+tidy_tempfile() {
+ if [ "$saved_stdin" -eq 1 ]; then
+ rm "$tempfile"
+ fi
+}
+
+if [ ! -f "$target" ]; then
+ printf "%s: file does not exist\n" "$target" >&2
exit 1
fi
if [ "$samename" -eq 1 ]; then
- override_rname="$(basename "$1")"
+ override_rname="$(basename "$target")"
fi
-REMOTE="do"
-URLBASE="https://ubq323.website/files/"
-REMOTEDIR="/srv/web/ubq/files/"
-ext="${1#*.}"
-if [ "$ext" = "$1" ]; then
+ext="${target#*.}"
+if [ "$ext" = "$target" ]; then
ext='.file'
- bname="$(basename "$1")"
+ bname="$(basename "$target")"
else
ext=".$ext"
- bname="$(basename "$1" "$ext")"
+ bname="$(basename "$target" "$ext")"
fi
ext=${override_ext:-$ext}
-rbname="$(md5sum "$1"|cut -d' ' -f1|tr 'a-z' 'A-Z'|basenc -d --base16|basenc --base64url|head -c8)"
+rbname="$(md5sum "$target"|cut -d' ' -f1|tr 'a-z' 'A-Z'|basenc -d --base16|basenc --base64url|head -c8)"
rname="${override_rname:-$rbname$ext}"
exists_already() {
@@ -75,10 +93,11 @@ done
printf 'uploading to %s\n' "$rname" >&2
if [ "$dry_run" -eq 1 ]; then
echo dryrun, not uploading anything
+ tidy_tempfile
exit 0
fi
-scp -q "$1" "${REMOTE}:$REMOTEDIR$rname"
+scp -q "$target" "${REMOTE}:$REMOTEDIR$rname"
ssh "$REMOTE" chmod a+r "$REMOTEDIR$rname"
url="$URLBASE$rname"
@@ -89,3 +108,5 @@ else
printf '%s\n' "$url"
fi
+tidy_tempfile
+