diff options
author | ubq323 <ubq323@ubq323.website> | 2023-04-28 02:30:33 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-04-28 02:30:33 +0100 |
commit | 6e3a1f376fbef9d0f6f8c72d6b22ff1d40e812ed (patch) | |
tree | 10829dd8d7c7125d511c270ba392e5c5812114d8 /.local/bin/rupload | |
parent | 4762791fad362c8afe1c9a2b1c555c6a8d7b79d1 (diff) |
movement
Diffstat (limited to '.local/bin/rupload')
-rwxr-xr-x | .local/bin/rupload | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/.local/bin/rupload b/.local/bin/rupload deleted file mode 100755 index c414b68..0000000 --- a/.local/bin/rupload +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh - -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 - printf '\t%s\n' "-p: print uploaded url instead of copying to clipboard and notifying" >&2 - printf '\t%s\n' "-x EXT: set extension to EXT on uploaded filename" >&2 - printf '\t%s\n' "-r NAME: set remote name to NAME including extension" >&2 - printf '\t%s\n' "-R: set remote name to basename of FILENAME" >&2 - exit 1 -fi - -dry_run=0 -samename=0 -printurl=0 -override_rname= -while [ $# -gt 1 ]; do - if [ "$1" = "-x" ]; then - override_ext=".$2" - shift 2 - elif [ "$1" = "-n" ]; then - dry_run=1 - shift - elif [ "$1" = "-p" ]; then - printurl=1 - shift - elif [ "$1" = "-r" ]; then - override_rname="$2" - shift 2 - elif [ "$1" = "-R" ]; then - samename=1 - shift - else - printf "%s: unrecognized argument %s\n" "$0" "$1" >&2 - exit 2 - fi -done - -if [ ! -f "$1" ]; then - printf %s "$1: file does not exist" >&2 - exit 1 -fi - -if [ "$samename" -eq 1 ]; then - override_rname="$(basename "$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 --base64url|head -c8)" -rname="${override_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" >&2 - rname="_$rname" -done - -printf 'uploading to %s\n' "$rname" >&2 -if [ "$dry_run" -eq 1 ]; then - echo dryrun, not uploading anything - exit 0 -fi - -scp -q "$1" "${REMOTE}:$REMOTEDIR$rname" -ssh "$REMOTE" chmod a+r "$REMOTEDIR$rname" - -url="$URLBASE$rname" -if [ "$printurl" -eq 0 ]; then - printf %s "$url" | wl-copy - notify-send 'copied url to clipboard' "$url" -else - printf '%s\n' "$url" -fi - |