Skip to content

Commit 4c856c6

Browse files
author
Mattchis
committed
- 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.
1 parent 80b3169 commit 4c856c6

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

rmmagent-linux.sh

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,13 @@ rmm_agent_type=$8
126126
## Uninstall var for easy scription
127127
mesh_fqdn=$2
128128
mesh_id=$3
129+
## Setting Go verison to be installed
130+
go_version="1.21.5"
129131

130-
go_url_amd64="https://go.dev/dl/go1.21.5.linux-amd64.tar.gz"
131-
go_url_x86="https://go.dev/dl/go1.21.5.linux-386.tar.gz"
132-
go_url_arm64="https://go.dev/dl/go1.21.5.linux-arm64.tar.gz"
133-
go_url_armv6="https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz"
132+
go_url_amd64="https://go.dev/dl/go$go_version.linux-amd64.tar.gz"
133+
go_url_x86="https://go.dev/dl/go$go_version.linux-386.tar.gz"
134+
go_url_arm64="https://go.dev/dl/go$go_version.linux-arm64.tar.gz"
135+
go_url_armv6="https://go.dev/dl/go$go_version.linux-armv6l.tar.gz"
134136

135137
function go_install() {
136138
if ! command -v go &> /dev/null; then
@@ -156,9 +158,40 @@ function go_install() {
156158
export GOPATH=/usr/local/go
157159
export GOCACHE=/root/.cache/go-build
158160

159-
echo "Golang Install Done !"
161+
echo "Go is installed (version $go_current_version)."
160162
else
161-
echo "Go is already installed"
163+
# Get the current version of Go installed
164+
go_current_version=$(go version | awk '{print $3}' | sed 's/go//')
165+
166+
if [ "$go_current_version" != "$go_version" ]; then
167+
echo "Version mismatch. Current installed version is $go_current_version. Desired version is $go_version."
168+
echo "Installing Go $go_version..."
169+
## Installing golang
170+
case $system in
171+
amd64)
172+
wget -O /tmp/golang.tar.gz $go_url_amd64
173+
;;
174+
x86)
175+
wget -O /tmp/golang.tar.gz $go_url_x86
176+
;;
177+
arm64)
178+
wget -O /tmp/golang.tar.gz $go_url_arm64
179+
;;
180+
armv6)
181+
wget -O /tmp/golang.tar.gz $go_url_armv6
182+
;;
183+
esac
184+
185+
rm -rvf /usr/local/go/
186+
tar -xvzf /tmp/golang.tar.gz -C /usr/local/
187+
rm /tmp/golang.tar.gz
188+
export GOPATH=/usr/local/go
189+
export GOCACHE=/root/.cache/go-build
190+
191+
echo "Go $go_version installed."
192+
else
193+
echo "Go is up to date (version $go_current_version)."
194+
fi
162195
fi
163196
}
164197

0 commit comments

Comments
 (0)