-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
94 lines (76 loc) · 1.85 KB
/
install.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
set -e
INSTALL_DIR="/usr/local/bin"
RELEASE="latest"
# Parse Flags
parse_args() {
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-r | --release)
RELEASE="$2"
shift # past release argument
shift # past release value
;;
*)
echo "Unrecognized argument $key"
exit 1
;;
esac
done
}
set_filename() {
local OS
OS=$(uname -s)
if [ "$OS" == "Linux" ]; then
FILENAME="query-json-linux-x64"
elif [ "$OS" == "Darwin" ]; then
FILENAME="query-json-darwin-x64"
else
echo "OS $OS is not supported."
echo "If you think that's a bug - please file an issue to https://github.com/davesnx/query-json/issues"
exit 1
fi
}
download() {
if [ "$RELEASE" == "latest" ]; then
URL=https://github.com/davesnx/query-json/releases/latest/download/$FILENAME.zip
else
URL=https://github.com/davesnx/query-json/releases/download/$RELEASE/$FILENAME.zip
fi
DOWNLOAD_DIR=$(mktemp -d)
echo "Downloading $URL..."
mkdir -p "$INSTALL_DIR" &>/dev/null
curl --progress-bar -L "$URL" -o "$DOWNLOAD_DIR/$FILENAME.zip"
if [ 0 -ne "$?" ]; then
echo "Download failed. Check that the release/filename are correct."
exit 1
fi
unzip -q "$DOWNLOAD_DIR/$FILENAME.zip" -d "$DOWNLOAD_DIR"
mv "$DOWNLOAD_DIR/query-json" "$INSTALL_DIR/query-json"
chmod u+x "$INSTALL_DIR/query-json"
}
check_dependencies() {
echo "Checking dependencies for the installation script..."
echo -n "Checking availability of curl... "
if hash curl 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
echo -n "Checking availability of unzip... "
if hash unzip 2>/dev/null; then
echo "OK!"
else
echo "Missing!"
SHOULD_EXIT="true"
fi
if [ "$SHOULD_EXIT" = "true" ]; then
exit 1
fi
}
parse_args "$@"
set_filename
check_dependencies
download