@@ -13,18 +13,21 @@ print_usage(){
13
13
14
14
usage:
15
15
16
- $( basename $0 ) /path/to/file Github_user_name
17
-
18
- or
19
-
20
- lsusb | $( basename $0 ) Github_user_name
16
+ $( basename $0 ) /path/to/file your_token
21
17
22
18
or
23
19
24
20
lsusb | $( basename $0 ) your_token
25
21
26
- If no credential is passed and $config_file is found,
27
- contents of config file is used.
22
+ If no token is passed and $config_file is found,
23
+ contents of config file is used as the token, so
24
+ the usage becomes:
25
+
26
+ lsusb | $( basename $0 )
27
+
28
+ or
29
+
30
+ $( basename $0 ) /path/to/file
28
31
29
32
USAGE
30
33
}
@@ -33,24 +36,28 @@ USAGE
33
36
FNAME=" ${1:- } "
34
37
if [[ -f " $FNAME " ]]; then
35
38
CONTENT=$( cat " $FNAME " )
36
- CREDENTIAL =" ${2:- } "
39
+ TOKEN =" ${2:- } "
37
40
else
38
41
CONTENT=$( timeout 2 cat -)
39
- CREDENTIAL =" ${1-} "
42
+ TOKEN =" ${1-} "
40
43
FNAME=" stdin"
41
44
if [[ " $CONTENT " == " " ]]; then
45
+ echo " ERROR: Content is empty"
46
+ echo
42
47
print_usage
43
48
exit 2
44
49
fi
45
50
fi
46
51
47
- if [[ -z $CREDENTIAL ]] && [[ -f $config_file ]]; then
52
+ if [[ -z $TOKEN ]] && [[ -f $config_file ]]; then
48
53
echo " Using $config_file for credentials"
49
- CREDENTIAL =$( cat $config_file )
54
+ TOKEN =$( cat $config_file )
50
55
fi
51
56
52
57
# Github does not permit anonymous uploads since April 2018
53
- if [[ -z $CREDENTIAL ]]; then
58
+ if [[ -z $TOKEN ]]; then
59
+ echo " ERROR: Token is missing."
60
+ echo
54
61
print_usage
55
62
exit 2
56
63
fi
@@ -82,15 +89,9 @@ cat > $tmp_file <<EOF
82
89
EOF
83
90
84
91
# 4. Use curl to make a POST request
85
- if [[ ${# CREDENTIAL} -eq 40 ]]; then
86
- echo " Using token authentication."
87
- OUTPUT=$( curl -H " Authorization: token ${CREDENTIAL} " \
88
- -X POST -d @$tmp_file " https://api.github.com/gists" )
89
- else
90
- echo " Using username/password authentication."
91
- OUTPUT=$( curl -u ${CREDENTIAL} \
92
- -X POST -d @$tmp_file " https://api.github.com/gists" )
93
- fi
92
+ OUTPUT=$( curl -H " Authorization: token ${TOKEN} " \
93
+ -X POST -d @$tmp_file " https://api.github.com/gists" )
94
+
94
95
uploaded_url=$( echo " $OUTPUT " | grep ' html_url' | grep ' gist' )
95
96
96
97
# 5. cleanup the tmp file
0 commit comments