Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit b992f4f

Browse files
c4s4Michel Casabianca
andauthored
Fixed installation script (#15)
Co-authored-by: Michel Casabianca <michel.casabianca@intercloud.com>
1 parent e269a08 commit b992f4f

1 file changed

Lines changed: 43 additions & 89 deletions

File tree

install

Lines changed: 43 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,115 +4,69 @@
44
#
55
# $ sh -c "$(curl -L https://github.com/intercloud/gobinsec/releases/latest/download/install)"
66
#
7+
# or (if you don't have curl installed):
8+
#
9+
# $ sh -c "$(wget -O - https://github.com/intercloud/gobinsec/releases/latest/download/install)"
710

811
set -e
912

10-
log() {
11-
echo "$@"
12-
}
13-
14-
logF() {
15-
echo >&2 "$@"
16-
exit 1
17-
}
18-
19-
repo="gobinsec"
20-
owner="intercloud"
21-
binary="${repo}"
22-
23-
get_os() {
24-
echo $(uname -s | awk '{print tolower($0)}')
25-
}
26-
27-
get_arch() {
28-
a=$(uname -m)
29-
case ${a} in
30-
"x86_64" | "amd64")
31-
echo "x86_64"
32-
;;
33-
"i386" | "i486" | "i586")
34-
echo "i386"
35-
;;
36-
*)
37-
echo ${NIL}
38-
;;
39-
esac
40-
}
41-
42-
if [ -z "$githubUrl" ]; then
43-
githubUrl="https://github.com"
44-
fi
45-
46-
# parse flag
47-
for i in "$@"; do
48-
case $i in
49-
-v=* | --version=*)
50-
version="${i#*=}"
51-
shift
52-
;;
53-
*)
54-
# unknown option
55-
;;
56-
esac
57-
done
58-
59-
if [ -z "$version" ]; then
60-
version="latest"
61-
fi
13+
NAME="gobinsec"
6214

63-
# get OS and ARCH and build binary name
64-
os=$(get_os)
65-
arch=$(get_arch)
15+
# get OS and ARCH and build archive name
16+
os=`uname | tr '[:upper:]' '[:lower:]'`
17+
arch=`uname -m`
6618

67-
log "os: ${os}"
68-
log "arch: ${arch}"
69-
log "version: ${version:-latest}"
19+
echo "os: ${os}"
20+
echo "arch: ${arch}"
7021

71-
fileName="${binary}_${os}_${arch}.tar.gz"
22+
archive="${NAME}_${os}_${arch}.tar.gz"
7223

7324
# set default installation directory
7425
if [ -d "/opt/local/bin" ]; then
75-
executableFolder="/opt/local/bin"
26+
DEFAULT_DIR="/opt/local/bin"
7627
elif [ -d "/opt/bin" ]; then
77-
executableFolder="/opt/bin"
28+
DEFAULT_DIR="/opt/bin"
7829
elif [ -d "/usr/local/bin" ]; then
79-
executableFolder="/usr/local/bin"
30+
DEFAULT_DIR="/usr/local/bin"
8031
elif [ -d "/usr/bin" ]; then
81-
executableFolder="/usr/bin"
32+
DEFAULT_DIR="/usr/bin"
8233
else
83-
executableFolder="/bin"
34+
DEFAULT_DIR="/bin"
8435
fi
8536

86-
# check command availability
87-
command -v curl >/dev/null 2>&1 || { logF "curl is required"; }
37+
# select command to download archive
38+
if hash curl 2>/dev/null
39+
then
40+
command="curl -L -o"
41+
elif hash wget 2>/dev/null
42+
then
43+
command="wget -O"
44+
else
45+
echo "You must install curl or wget to run this installation script"
46+
exit 1
47+
fi
8848

89-
# Set URI to download
90-
assetUri="${githubUrl}/${owner}/${repo}/releases/download/${version}/${fileName}"
91-
if [[ "${version}" == "latest" ]]; then
49+
# download archive in /tmp/${NAME}, unzip it and clean files
50+
${command} /tmp/${archive} https://github.com/intercloud/${NAME}/releases/latest/download/${archive}
9251

93-
asset=$(
94-
curl -sSf ${githubUrl}/${owner}/${repo}/releases |
95-
grep -o "${owner}/${repo}/releases/download/.*/${fileName}" |
96-
head -n 1
97-
)
52+
cd /tmp/
53+
tar -zxf $archive
54+
rm $archive LICENSE.txt README.md
9855

99-
assetUri="${githubUrl}/${asset}"
56+
# prompt for installation directory
57+
read -p "Installation directory [${DEFAULT_DIR}]? " directory
58+
if [ -z "$directory" ]
59+
then
60+
directory=${DEFAULT_DIR}
10061
fi
10162

102-
downloadFolder="/tmp/${binary}"
103-
mkdir -p ${downloadFolder}
104-
downloadedFile="${downloadFolder}/${fileName}"
105-
106-
log "[1/2] Download ${assetUri}"
107-
curl -sS --fail --location --output "${downloadedFile}" "${assetUri}"
108-
109-
log "[2/2] Install ${binary} to '${executableFolder}'"
110-
if [ -w "${directory}" ]; then
111-
tar -xz -f ${downloadedFile} -C ${executableFolder}
112-
chmod +x ${executableFolder}/${binary}
63+
# copy binary to installation directory
64+
if [ -w "${directory}" ]
65+
then
66+
mv /tmp/${NAME} ${directory}
11367
else
114-
sudo tar -xz -f ${downloadedFile} -C ${executableFolder}
115-
sudo chmod +x ${executableFolder}/${binary}
68+
sudo mv /tmp/${NAME} ${directory}
69+
sudo chown root: ${directory}/${NAME}
11670
fi
11771

118-
echo "${binary} installed in '${executableFolder}' directory"
72+
echo "${NAME} installed in '${directory}' directory"

0 commit comments

Comments
 (0)