forked from streamnative/pulsarctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·172 lines (143 loc) · 3.87 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
#
#/**
# * Licensed to the Apache Software Foundation (ASF) under one
# * or more contributor license agreements. See the NOTICE file
# * distributed with this work for additional information
# * regarding copyright ownership. The ASF licenses this file
# * to you under the Apache License, Version 2.0 (the
# * "License"); you may not use this file except in compliance
# * with the License. You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# */
set -e
if [[ "x${version}" == "x" ]]; then
version=$(curl -s https://raw.githubusercontent.com/streamnative/pulsarctl/master/stable.txt)
fi
discoverArch() {
ARCH=$(uname -m)
case $ARCH in
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
esac
}
usage() {
cat <<EOF
This script is used to install pulsarctl
Options:
-h,--help Prints the usage message
-u,--user Install to the user install directory for your platform. Typically '$HOME/.pulsarctl/pulsarctl'.
-v,--version Install a specific version of pulsarctl
EOF
}
userOnly=false
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-u|--user)
userOnly=true
shift
;;
-v|--version)
version="$2"
shift
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown option: $key"
usage
exit 1
;;
esac
done
discoverArch
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
copyBinary() {
target_dir=/usr/local/bin
if [[ "${userOnly}" == "true" ]]; then
target_dir=${HOME}/.pulsarctl
mkdir -p ${target_dir}
fi
target_binary_file=pulsarctl${version}
target_binary_file_path=${target_dir}/${target_binary_file}
if [[ -f ${target_binary_file_path} ]]; then
rm ${target_binary_file_path}
fi
mv pulsarctl ${target_binary_file_path}
chmod +x ${target_binary_file_path}
if [[ -f ${target_dir}/pulsarctl ]];then
rm ${target_dir}/pulsarctl
fi
ln -s ${target_binary_file} ${target_dir}/pulsarctl
}
installNew() {
TARFILE=pulsarctl-${ARCH}-${OS}.tar.gz
UNTARFILE=pulsarctl-${ARCH}-${OS}
if [[ -f ${TARFILE} ]]; then
rm -f ${TARFILE}
fi
if [[ -d ${UNTARFILE} ]]; then
rm -rf ${UNTARFILE}
fi
if [[ -f ${UNTARFILE} ]]; then
rm -f ${UNTARFILE}
fi
curl --retry 10 -L -o ${TARFILE} https://github.com/streamnative/pulsarctl/releases/download/${version}/${TARFILE}
tar -xzf ${TARFILE}
pushd ${UNTARFILE}
copyBinary
local plugins_dir=${HOME}/.pulsarctl/plugins
mkdir -p ${plugins_dir}
cp -r plugins/* ${plugins_dir}
rm -rf ${TARFILE}
rm -rf ${UNTARFILE}
echo "The plugins of pulsarctl ${version} are successfully installed under directory '${plugins_dir}'."
echo
echo "In order to use this plugins, please add the plugin directory '${plugins_dir}' to the system PATH. You can do so by adding the following line to your bash profile."
echo
echo 'export PATH=${PATH}:${HOME}/.pulsarctl/plugins'
echo
echo "Happy Pulsaring!"
export PATH=${HOME}/.pulsarctl:${HOME}/.pulsarctl/plugins:${PATH}
popd
}
installOld() {
binary=pulsarctl-${ARCH}-${OS}
if [[ -d ${binary} ]]; then
rm -rf ${binary}
fi
if [[ -f ${binary} ]]; then
rm -f ${binary}
fi
curl --retry 10 -L -o ${binary} https://github.com/streamnative/pulsarctl/releases/download/${version}/${binary}
mv ${binary} pulsarctl
copyBinary
echo "Happy Pulsaring!"
}
case $version in
v0.1.0)
installOld
;;
v0.2.0)
installOld
;;
v0.3.0)
installOld
;;
*)
installNew
esac