-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-wakatime.sh
executable file
·72 lines (60 loc) · 1.8 KB
/
install-wakatime.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
#!/bin/sh
# templated by http://qiita.com/blackenedgold/items/c9e60e089974392878c8
usage() {
cat <<HELP
NAME:
$0 -- install wakatime
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
}
wakatime_version() {
wakatime --version | grep -Eo '[0-9.]+'
}
main() {
SCRIPT_DIR="$(cd $(dirname "$0"); pwd)"
: ${PREFIX=~/bin}
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 = $(wakatime_version) , required version = ${VERSION}"
if "$force" || [ "$(wakatime_version)" != "${VERSION}" ]; then
echo "start installing $VERSION"
wget "https://github.com/wakatime/wakatime-cli/releases/download/v$VERSION/wakatime-cli-linux-amd64.zip"
mkdir "wakatime_${VERSION}_linux_amd64"
unzip wakatime-cli-linux-amd64.zip -d "wakatime_${VERSION}_linux_amd64"
cp "wakatime_${VERSION}_linux_amd64/wakatime-cli-linux-amd64" "$PREFIX/wakatime"
rm -rf "wakatime_${VERSION}_linux_amd64" "wakatime-cli-linux-amd64.zip"
echo "installation of wakatime ${VERSION} done"
else
echo "wakatime is up to date. do nothing."
fi
}
main "$@"