#!/bin/sh # ==== DELETE THIS LINES ===== echo "NOTHING HAPPENED!" echo "FIRST READ THE SCRIPT!" exit # ============================ set -e host="https://x.nopwd.lol" links="$HOME/.local/null-links.txt" exp="1" sec="" prog="${0##*/}" usage() { cat <<-_EOF Usage: $prog [option] [file|url] Options: -l long link -s shorten url -e [hour] expire time Examples: # upload file $prog somefile.png # expire time 24 hours $prog -e 24 somefile.png # upload piped data echo "something" | $prog - # get long link $prog -l somefile.png # shorten url $prog -s https://verylongurl # combine expire and long $prog -e 5 -s somefile.txt _EOF exit } if [ $1 = "-e" ]; then exp=$2 shift 2 fi if [ $# -ge 3 ] || [ $# -eq 0 ]; then usage fi if [ $# -eq 2 ]; then case $1 in -s) url=$(curl -s -Fshorten=$2 $host) echo $url echo -e "$url\t# shorten: $2" >> $links exit ;; -l) long="secret=" shift ;; *) echo "$prog: unrecognized option '$1'" usage ;; esac fi if [ -f $1 ] || [ $1 = "-" ]; then out=$(curl -s -Ffile=@$1 -F$long -Fexpires=$exp -w '%header{x-token}' $host) else echo "$prog: file '$1' not exist" exit fi url=$(echo "$out" | sed '1q;d') token=$(echo "$out" | sed '2q;d') echo $url echo -e "$url\t\t# expire: $exp, token: $token" >> $links