aboutsummaryrefslogtreecommitdiff
path: root/bin/null.sh
blob: 938913c80d0ec0638607943cf54946adbf16ac4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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