From 80b3169cd0d6f14236be53bfa3f9f404854821c7 Mon Sep 17 00:00:00 2001 From: Mattchis Date: Tue, 12 Dec 2023 12:36:11 -0700 Subject: [PATCH 1/2] - Updated go to 1.21.5 - Added to remove /usr/local/go/ before install go. In some situations there was a compiling issue with go with a previous version installed. --- rmmagent-linux.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rmmagent-linux.sh b/rmmagent-linux.sh index 6aba189..e1b8afc 100644 --- a/rmmagent-linux.sh +++ b/rmmagent-linux.sh @@ -127,10 +127,10 @@ rmm_agent_type=$8 mesh_fqdn=$2 mesh_id=$3 -go_url_amd64="https://go.dev/dl/go1.18.3.linux-amd64.tar.gz" -go_url_x86="https://go.dev/dl/go1.18.3.linux-386.tar.gz" -go_url_arm64="https://go.dev/dl/go1.18.3.linux-arm64.tar.gz" -go_url_armv6="https://go.dev/dl/go1.18.3.linux-armv6l.tar.gz" +go_url_amd64="https://go.dev/dl/go1.21.5.linux-amd64.tar.gz" +go_url_x86="https://go.dev/dl/go1.21.5.linux-386.tar.gz" +go_url_arm64="https://go.dev/dl/go1.21.5.linux-arm64.tar.gz" +go_url_armv6="https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz" function go_install() { if ! command -v go &> /dev/null; then @@ -150,6 +150,7 @@ function go_install() { ;; esac + rm -rvf /usr/local/go/ tar -xvzf /tmp/golang.tar.gz -C /usr/local/ rm /tmp/golang.tar.gz export GOPATH=/usr/local/go From 4c856c64f73046fe7c85a077fd72053a0a9314d0 Mon Sep 17 00:00:00 2001 From: Mattchis Date: Tue, 12 Dec 2023 13:12:01 -0700 Subject: [PATCH 2/2] - Added a variable to specify the Go version. - Added a condition that will check the defined version Go with the version of Go installed on the system. Based on this condition either the defined version of Go gets installed or not. --- rmmagent-linux.sh | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/rmmagent-linux.sh b/rmmagent-linux.sh index e1b8afc..dfe3f55 100644 --- a/rmmagent-linux.sh +++ b/rmmagent-linux.sh @@ -126,11 +126,13 @@ rmm_agent_type=$8 ## Uninstall var for easy scription mesh_fqdn=$2 mesh_id=$3 +## Setting Go verison to be installed +go_version="1.21.5" -go_url_amd64="https://go.dev/dl/go1.21.5.linux-amd64.tar.gz" -go_url_x86="https://go.dev/dl/go1.21.5.linux-386.tar.gz" -go_url_arm64="https://go.dev/dl/go1.21.5.linux-arm64.tar.gz" -go_url_armv6="https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz" +go_url_amd64="https://go.dev/dl/go$go_version.linux-amd64.tar.gz" +go_url_x86="https://go.dev/dl/go$go_version.linux-386.tar.gz" +go_url_arm64="https://go.dev/dl/go$go_version.linux-arm64.tar.gz" +go_url_armv6="https://go.dev/dl/go$go_version.linux-armv6l.tar.gz" function go_install() { if ! command -v go &> /dev/null; then @@ -156,9 +158,40 @@ function go_install() { export GOPATH=/usr/local/go export GOCACHE=/root/.cache/go-build - echo "Golang Install Done !" + echo "Go is installed (version $go_current_version)." else - echo "Go is already installed" + # Get the current version of Go installed + go_current_version=$(go version | awk '{print $3}' | sed 's/go//') + + if [ "$go_current_version" != "$go_version" ]; then + echo "Version mismatch. Current installed version is $go_current_version. Desired version is $go_version." + echo "Installing Go $go_version..." + ## Installing golang + case $system in + amd64) + wget -O /tmp/golang.tar.gz $go_url_amd64 + ;; + x86) + wget -O /tmp/golang.tar.gz $go_url_x86 + ;; + arm64) + wget -O /tmp/golang.tar.gz $go_url_arm64 + ;; + armv6) + wget -O /tmp/golang.tar.gz $go_url_armv6 + ;; + esac + + rm -rvf /usr/local/go/ + tar -xvzf /tmp/golang.tar.gz -C /usr/local/ + rm /tmp/golang.tar.gz + export GOPATH=/usr/local/go + export GOCACHE=/root/.cache/go-build + + echo "Go $go_version installed." + else + echo "Go is up to date (version $go_current_version)." + fi fi }