Skip to content

Commit

Permalink
feature:makefile - add install-beta and install-rc
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Cardoso <ian.cardoso@zup.com.br>
  • Loading branch information
iancardosozup committed Nov 29, 2021
1 parent a461416 commit 624c7a8
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PATH_BINARY_BUILD_CLI ?= $(GOPATH)/bin
ARCH_ARM64 ?= arm64
ARCH_AMD64 ?= amd64
MAIN = ./cmd/app
LATEST_RC= $$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-rc.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')
LATEST_BETA= $$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-beta.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')

lint:
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Expand Down Expand Up @@ -137,4 +139,10 @@ build-install-stand-alone-cli-windows:
install:
./deployments/scripts/install.sh latest

install-beta:
./deployments/scripts/install.sh $(LATEST_BETA)

install-rc:
./deployments/scripts/install.sh $(LATEST_RC)

pipeline: fmt fix-imports lint test coverage security
102 changes: 102 additions & 0 deletions deployments/scripts/install-beta-rc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/sh
# Copyright 2020 ZUP IT SERVICOS EM TECNOLOGIA E INOVACAO SA
#
# Licensed 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.


URL_DOWNLOAD=""
VERSION_DOWNLOAD=$1
LATEST_RC=$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-rc.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')
LATEST_BETA=$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-beta.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')

horusecSetVersion () {
if [ -z "$LATEST_RC" ] || [ -z "$LATEST_BETA" ]; then
echo "horusec still don't have rc and beta versions"
exit 1
fi
if [ -z "$VERSION_DOWNLOAD" ]; then
echo "invalid input, empty string"
exit 1
elif [ "$VERSION_DOWNLOAD" != "rc" ] && [ "$VERSION_DOWNLOAD" != "beta" ]; then
echo "invalid input, use 'rc' or 'beta'"
exit 1
fi
if [ "$VERSION_DOWNLOAD" = "rc" ] ; then
echo "Version set to $LATEST_RC"
VERSION_DOWNLOAD=$LATEST_RC
fi
if [ "$VERSION_DOWNLOAD" = "beta" ] ; then
echo "Version set to $LATEST_BETA"
VERSION_DOWNLOAD=$LATEST_BETA
fi
echo "Download version: $VERSION_DOWNLOAD"
}

horusecIdentifyOSWithVersion () {
if [ "$(uname)" = "Linux" ]; then
if [ "$(uname -m)" = "x86_64" ]; then
echo "Installing Horusec for Linux x64"
URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_linux_x64"
elif [ "$(uname -m)" = "aarch64" ]; then
echo "Installing Horusec for Linux x64"
URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_linux_arm64"
else
echo "Installing Horusec for Linux x86"
URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_linux_x64"
fi
elif [ "$(uname)" = "Darwin" ]; then
if [ "$(uname -m)" = "x86_64" ]; then
echo "Installing Horusec for Mac x64"
URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_mac_x64"
elif [ "$(uname -m)" = "x86_64" ]; then
echo "Installing Horusec for Mac M1"
URL_DOWNLOAD="https://github.com/ZupIT/horusec/releases/download/${VERSION_DOWNLOAD}/horusec_mac_arm64"
else
echo "Not enable Horusec to Mac x86"
exit 1
fi
else
echo "Unable to identify which OS you're using"
exit 1
fi
}

horusecDownloadAndInstall () {
INSTALL_PATH="/usr/local/bin"

if [ ! -d "$INSTALL_PATH" ]; then
mkdir -p $INSTALL_PATH
fi

rm -r $INSTALL_PATH/horusec >/dev/null 2>&1

echo "Downloading horusec..."
echo $URL_DOWNLOAD

curl -fsSL "$URL_DOWNLOAD" -o ./horusec

chmod +x ./horusec

sudo mv ./horusec "$INSTALL_PATH"

echo "Horusec was downloaded and moved to $INSTALL_PATH/horusec"

$INSTALL_PATH/horusec version
}


horusecSetVersion

horusecIdentifyOSWithVersion

horusecDownloadAndInstall

0 comments on commit 624c7a8

Please sign in to comment.