diff options
Diffstat (limited to 'bin/null.sh')
-rwxr-xr-x | bin/null.sh | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/bin/null.sh b/bin/null.sh new file mode 100755 index 0000000..938913c --- /dev/null +++ b/bin/null.sh @@ -0,0 +1,88 @@ +#!/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 |