tangled
alpha
login
or
join now
jcs.org
/
dotfiles
0
fork
atom
ftp -o - https://jcs.org/move_in | sh -
0
fork
atom
overview
issues
pulls
pipelines
bin/imgur: add
jcs.org
1 year ago
4561b85e
9072e3ca
+38
1 changed file
expand all
collapse all
unified
split
bin
imgur
+38
bin/imgur
···
1
1
+
#!/bin/sh
2
2
+
#
3
3
+
# visit
4
4
+
# https://api.imgur.com/oauth2/addclient
5
5
+
# and register an application with auth type "oauth 2 without a callback"
6
6
+
#
7
7
+
# then visit
8
8
+
# https://api.imgur.com/oauth2/authorize?client_id=#YOUR_CLIENT_ID#&response_type=token
9
9
+
#
10
10
+
# after auth, you'll be redirected to an imgur.com url, save the access_token
11
11
+
# and `export IMGUR_ACCESS_TOKEN=(access token here)`
12
12
+
#
13
13
+
14
14
+
if [ X"${IMGUR_ACCESS_TOKEN}" = X"" ]; then
15
15
+
echo "\$IMGUR_ACCESS_TOKEN not set"
16
16
+
exit 1
17
17
+
fi
18
18
+
19
19
+
TMP=`mktemp /tmp/imgur.XXXXXX`
20
20
+
21
21
+
curl \
22
22
+
-s \
23
23
+
-o $TMP \
24
24
+
-X POST \
25
25
+
-H "Authorization: Bearer ${IMGUR_ACCESS_TOKEN}" \
26
26
+
-F "image=@${1}" \
27
27
+
https://api.imgur.com/3/upload
28
28
+
29
29
+
URL=`sed -e 's/.*"link":"//' -e 's/".*//' < $TMP`
30
30
+
31
31
+
if [ X"$URL" = "" ]; then
32
32
+
echo "failed parsing JSON output:"
33
33
+
cat $TMP
34
34
+
else
35
35
+
echo $URL
36
36
+
fi
37
37
+
38
38
+
rm $TMP