From 735782be32c6fca65a0b2bd8c4310533d57b610a Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sun, 16 Apr 2023 12:18:31 +0100 Subject: initial commit of dot files --- .local/bin/rupload | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 .local/bin/rupload (limited to '.local/bin/rupload') diff --git a/.local/bin/rupload b/.local/bin/rupload new file mode 100755 index 0000000..925fc0e --- /dev/null +++ b/.local/bin/rupload @@ -0,0 +1,65 @@ +#!/bin/sh + +if [ $# -eq 0 ]; then + printf '%s\n' "usage: $0 [-n] [-x override_ext] " >&2 + printf '\t%s\n' "-n: dry run (don't actually upload anything)" >&2 + printf '\t%s\n' "-x override_ext: set extension to override_ext on uploaded filename" >&2 + exit 1 +fi + +dry_run=0 +while [ $# -gt 1 ]; do + if [ "$1" = "-x" ]; then + override_ext=".$2" + shift 2 + elif [ "$1" = "-n" ]; then + dry_run=1 + shift + fi +done + +if [ ! -f "$1" ]; then + printf %s "$1: file does not exist" >&2 + exit 1 +fi + +REMOTE="do" +URLBASE="https://ubq323.website/files/" +REMOTEDIR="/srv/web/ubq/files/" + +ext="${1#*.}" +if [ "$ext" = "$1" ]; then + ext='.file' + bname="$(basename "$1")" +else + ext=".$ext" + bname="$(basename "$1" "$ext")" +fi +ext=${override_ext:-$ext} + +rbname="$(md5sum "$1"|cut -d' ' -f1|tr 'a-z' 'A-Z'|basenc -d --base16|basenc --base64|head -c8)" +rname="$rbname$ext" + +exists_already() { + ssh "$REMOTE" stat "$REMOTEDIR$1" 2>/dev/null >/dev/null + return $? +} + +while exists_already "$rname"; do + printf "%s exists already\n" "$rname" + rbname="${rbname}_" + rname="$rbname$ext" +done + +printf 'uploading to %s\n' "$rname" +if [ "$dry_run" -eq 1 ]; then + echo dryrun, not uploading anything + exit 0 +fi + +scp "$1" "${REMOTE}:$REMOTEDIR$rname" +ssh "$REMOTE" chmod a+r "$REMOTEDIR$rname" + +url="$URLBASE$rname" +printf %s "$url" | wl-copy +notify-send 'copied url to clipboard' "$url" -- cgit v1.2.3