Skip to content
This repository was archived by the owner on Dec 15, 2023. It is now read-only.

Commit 70af54b

Browse files
committed
feat: add install script
1 parent 9f7583a commit 70af54b

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

install.sh

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/bin/sh
2+
3+
NO_COLOR=$'\e[0m'
4+
ERROR=$'\e[0;31m'"ERROR: "
5+
INFO=$'\e[0;32m'"INFO: "
6+
WARN=$'\e[0;33m'"WARN: "
7+
LATEST_RELEASE="https://api.github.com/repos/francis-du/iotdb-cli/releases/latest"
8+
BIN_PATH="/usr/local/bin"
9+
VERSION=$1
10+
11+
set_version() {
12+
if [ ! -n "${VERSION}" ]; then
13+
status=$(curl -Is ${LATEST_RELEASE} | grep 'HTTP' | awk '{print $2}')
14+
if [ $status != 200 ]; then
15+
echo "${ERROR}Install failed, reason: $(curl -s ${LATEST_RELEASE} | grep '"message":' | awk '{print $0}')"
16+
exit 1
17+
fi
18+
19+
if command -v curl &>/dev/null; then
20+
VERSION=$(curl -s ${LATEST_RELEASE} | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
21+
else
22+
if command -v wget &>/dev/null; then
23+
VERSION=$(wget ${LATEST_RELEASE} | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
24+
else
25+
echo "${ERROR}Please install wget or curl${NO_COLOR}"
26+
exit 1
27+
fi
28+
fi
29+
fi
30+
}
31+
32+
download() {
33+
local url=$1
34+
local file_name=$2
35+
36+
if command -v curl &>/dev/null; then
37+
if [ -n $file_name ]; then
38+
if [ ! -f $file_name ]; then
39+
curl -L -f -# -C0 -o $file_name "$url"
40+
else
41+
command $file_name -h
42+
echo "${WARN}'$file_name' exists"
43+
echo "${WARN}Please run command 'iotdb' or '${file_name}'"
44+
exit 1
45+
fi
46+
else
47+
curl -L -f -# -OC0 "$url" --progress-bar
48+
fi
49+
else
50+
if command -v wget &>/dev/null; then
51+
command wget --spider -q "$url"
52+
if [ $? == 0 ]; then
53+
wget --spider -q "$url"
54+
if [ -n $file_name ]; then
55+
if [ ! -f $file_name ]; then
56+
wget -q -c --show-progress "$url" -O $file_name
57+
else
58+
command $file_name -h
59+
echo "${WARN}'$file_name' exists"
60+
echo "${WARN}Please run command 'iotdb' or '${file_name}'"
61+
exit 1
62+
fi
63+
else
64+
wget -q -c --show-progress "$url"
65+
fi
66+
else
67+
echo "${ERROR}Download failed from $url"
68+
exit 1
69+
fi
70+
else
71+
echo "${ERROR}Please install wget or curl${NO_COLOR}"
72+
exit 1
73+
fi
74+
fi
75+
}
76+
77+
function install() {
78+
set_version
79+
echo "${INFO}Version: ${VERSION}"
80+
echo "${INFO}Download from '${LATEST_RELEASE}'"
81+
asset_base_url="https://github.com/francis-du/iotdb-cli/releases/download/${VERSION}"
82+
case "$(uname -s)" in
83+
Linux*)
84+
bin_name="${BIN_PATH}/iotdb"
85+
asset_url="$asset_base_url/iotdb-linux"
86+
echo "${INFO}Assert url '${asset_url}'"
87+
download $asset_url $bin_name
88+
89+
if [ -f "${bin_name}" ]; then
90+
chmod +x $bin_name
91+
echo "${INFO}Please run command 'iotdb' or '${bin_name}'"
92+
else
93+
echo "${ERROR}Install failed"
94+
fi
95+
;;
96+
Darwin*)
97+
bin_name="${BIN_PATH}/iotdb"
98+
asset_url="${asset_base_url}/iotdb-mac"
99+
echo "${INFO}Assert url '${asset_url}'"
100+
download $asset_url $bin_name
101+
102+
if [ -f "${bin_name}" ]; then
103+
chmod +x $bin_name
104+
echo "${INFO}Please run command 'iotdb' or '${bin_name}'"
105+
else
106+
echo "${ERROR}Install failed"
107+
fi
108+
;;
109+
CYGWIN*)
110+
# TODO: Need to be test
111+
bin_name="${BIN_PATH}/iotdb.exe"
112+
asset_url="$asset_base_url/iotdb.exe"
113+
echo "${INFO}Assert url '${asset_url}'"
114+
download $asset_url $bin_name
115+
116+
if [ -f "${bin_name}" ]; then
117+
echo "${INFO}Please run command 'iotdb.exe' or '${bin_name}'"
118+
else
119+
echo "${ERROR}Install failed"
120+
fi
121+
;;
122+
MINGW*)
123+
# TODO: Need to be test
124+
bin_name="${BIN_PATH}/iotdb.exe"
125+
asset_url=$asset_base_url"/iotdb.exe"
126+
echo "${INFO}Assert url '${asset_url}'"
127+
download $asset_url $bin_name
128+
129+
if [ -f "${bin_name}" ]; then
130+
echo "${INFO}Please run command 'iotdb.exe' or '${bin_name}'"
131+
else
132+
echo "${ERROR}Install failed"
133+
fi
134+
;;
135+
*)
136+
echo "${ERROR}Unknown OS"
137+
;;
138+
esac
139+
}
140+
141+
install

0 commit comments

Comments
 (0)