This repository was archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgithub_cli.sh
executable file
·94 lines (83 loc) · 2.5 KB
/
github_cli.sh
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
89
90
91
92
93
94
#!/bin/bash -
#===============================================================================
#
# FILE: github_cli.sh
#
# USAGE: ./github_cli.sh
#
# DESCRIPTION:
#
# OPTIONS: See usage()
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Frederic Pillon (), [email protected]
# ORGANIZATION: MCU Embedded Software
# COPYRIGHT: Copyright (c) 2018, Frederic Pillon
# CREATED: 08/14/2018 08:07:43
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
VERSION="0.1"
GITHUB_ACCOUNT="stm32duino"
REPO_NAME="arm-none-eabi-gcc"
LATEST_RELEASE=1
###############################################################################
## Help function
usage()
{
echo "############################################################"
echo "##"
echo "## `basename $0`"
echo "##"
echo "############################################################"
echo "##"
echo "## `basename $0`"
echo "## [-l] [-h] [-v] [-a <github account>] [-r <repo name>]"
echo "##"
echo "## Mandatory options:"
echo "##"
echo "## None"
echo "##"
echo "## Optionnal:"
echo "##"
echo "## -a <github account>: github account name. Default: '$GITHUB_ACCOUNT'"
echo "## -r <repo name>: repository name. Default: '$REPO_NAME'"
echo "## -l: get latest release"
echo "## -v: print version"
echo "##"
echo "############################################################"
exit 0
}
get_latest_release() {
# Get latest release from GitHub api
curl --silent "https://api.github.com/repos/${GITHUB_ACCOUNT}/${REPO_NAME}/releases/latest" |
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# parse command line arguments
# options may be followed by one colon to indicate they have a required arg
options=`getopt -o a:hlr:v -- "$@"`
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
eval set -- "$options"
while true ; do
case "$1" in
-a) GITHUB_ACCOUNT=$2
shift 2;;
-h|-\?) usage
shift;;
-l) LATEST_RELEASE=1
shift;;
-r) REPO_NAME=$2
shift 2;;
-v) echo "`basename $0`: $VERSION"
exit 0
shift;;
--) shift;
break;;
*) break;;
esac
done
if [ $LATEST_RELEASE -eq 1 ]; then
get_latest_release
fi