-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-hub.sh
executable file
·71 lines (58 loc) · 1.64 KB
/
install-hub.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
#!/bin/sh
# templated by http://qiita.com/blackenedgold/items/c9e60e089974392878c8
usage() {
cat <<HELP
NAME:
$0 -- install hub
SYNOPSIS:
$0 [--force] [--verbose] VERSION
$0 [-h|--help]
DESCRIPTION:
install the hub
--force Skip version check and force install
-h --help Print this help.
--verbose Enables verbose mode.
HELP
}
hub_version() {
hub version | grep 'hub version' | grep -Eo '[0-9.]+'
}
main() {
SCRIPT_DIR="$(cd $(dirname "$0"); pwd)"
force=false
while [ $# -gt 0 ]; do
case "$1" in
--force) force=true; shift ;;
--help) usage; exit 0;;
--verbose) set -x; shift;;
--) shift; break;;
-*)
OPTIND=1
while getopts h OPT "$1"; do
case "$OPT" in
h) usage; exit 0;;
esac
done
shift
;;
*) break;;
esac
done
if [ $# != 1 ]; then
usage
exit 1
fi
VERSION="$1"
echo "current version = $(hub_version) , required version = ${VERSION}"
if "$force" || [ "$(hub_version)" != "${VERSION}" ]; then
echo "start installing $VERSION"
wget https://github.com/github/hub/releases/download/v${VERSION}/hub-linux-amd64-${VERSION}.tgz
tar xzf hub-linux-amd64-${VERSION}.tgz
(cd hub-linux-amd64-${VERSION} && sudo ./install)
rm -rf hub-linux-amd64-${VERSION}.tgz hub-linux-amd64-${VERSION}
echo "installation of hub ${VERSION} done"
else
echo "hub is up to date. do nothing."
fi
}
main "$@"