#!/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"