-
Notifications
You must be signed in to change notification settings - Fork 8
/
puush
executable file
·41 lines (38 loc) · 862 Bytes
/
puush
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
#!/bin/bash
if [ "$1" = "-" ]
then
if [ "$2" != "" ]
then
EXT=$2
else
EXT="txt"
fi
_IFS=$IFS
IFS='' # to preserve spacing
while read p
do
echo $p >> /tmp/puush-tmp.$EXT
done
IFS=$_IFS
FN="/tmp/puush-tmp.$EXT"
else
FN="$1"
fi
if [ -z "$PUUSH_API_KEY" ]
then
echo "Please enter your API key:"
read PUUSH_API_KEY
echo "export PUUSH_API_KEY=$PUUSH_API_KEY" >> ~/.bashrc
echo "Added API key to ~/.bashrc"
fi
if [ -z "$FN" ]
then
echo "Specify a file to be uploaded (or use - for stdin)"
exit 2
elif ! [ -f "$FN" -a -r "$FN" ]
then
echo "File '$FN' is not valid (it is not a file or it is not readable)"
exit 3
fi
curl "https://puush.me/api/up" -# -F "k=$PUUSH_API_KEY" -F "z=poop" -F "f=@$FN" | sed -E 's/^.+,(.+),.+,.+$/\1\n/'
rm /tmp/puush-tmp.* 2>/dev/null