diff options
Diffstat (limited to 'guix/kolwynia/home/bdunahu/files/.local/bin/upload')
| -rwxr-xr-x | guix/kolwynia/home/bdunahu/files/.local/bin/upload | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/guix/kolwynia/home/bdunahu/files/.local/bin/upload b/guix/kolwynia/home/bdunahu/files/.local/bin/upload new file mode 100755 index 0000000..a2db9b5 --- /dev/null +++ b/guix/kolwynia/home/bdunahu/files/.local/bin/upload @@ -0,0 +1,43 @@ +#!/bin/sh + + +err() { echo "Usage: + upload [OPTIONS] +Options: + -t: time from now to expire in hours (default: 48) + file: a path to a file. If this is not given, receives input from stdin." && exit 1 ;} + +hours=48 + +while getopts ":t:" opt; do + case $opt in + t) + hours=$OPTARG + if [[ $OPTARG =~ ^-?[0-9]+$ ]]; then + hours=$OPTARG + else + err + fi + ;; + *) + err + ;; + esac +done + +shift $((OPTIND -1)) + +if [ -n "$1" ] && [ -f "$1" ]; then + source="$1" + ext="${1##*.}" +else + source=$(mktemp) + ext="txt" + cat > "$source" + chmod a+r "$source" +fi + +dest="$(cat /dev/random | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1)-$(date -d "+$hours hours" +%s).$ext" + +scp "$source" "root@operationnull.com:/var/www/operationnull/paste/$dest" && + echo "https://operationnull.com/paste/$dest" |
