forked from rondoval/GoHeishaMon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo-installation.sh
49 lines (41 loc) · 1.43 KB
/
go-installation.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
#!/bin/bash
VERSION=1.20.4
ARCH=armv6l # arm64 for 64-bit OS, armv6l for 32-bit OS
## Download the latest version of Golang
echo "Downloading Go $VERSION"
wget https://dl.google.com/go/go$VERSION.linux-$ARCH.tar.gz
echo "Downloading Go $VERSION completed"
## Extract the archive
echo "Extracting..."
tar -C ~/.local/share -xzf go$VERSION.linux-$ARCH.tar.gz
echo "Extraction complete"
## Detect the user's shell and add the appropriate path variables
SHELL_TYPE=$(basename "$SHELL")
if [ "$SHELL_TYPE" = "zsh" ]; then
echo "Found ZSH shell"
SHELL_RC="$HOME/.zshrc"
elif [ "$SHELL_TYPE" = "bash" ]; then
echo "Found Bash shell"
SHELL_RC="$HOME/.bashrc"
elif [ "$SHELL_TYPE" = "fish" ]; then
echo "Found Fish shell"
SHELL_RC="$HOME/.config/fish/config.fish"
else
echo "Unsupported shell: $SHELL_TYPE"
exit 1
fi
echo 'export GOPATH=$HOME/.local/share/go' >> "$SHELL_RC"
echo 'export PATH=$HOME/.local/share/go/bin:$PATH' >> "$SHELL_RC"
## Verify the installation
if [ -x "$(command -v go)" ]; then
INSTALLED_VERSION=$(go version | awk '{print $3}')
if [ "$INSTALLED_VERSION" == "go$VERSION" ]; then
echo "Go $VERSION is installed successfully."
else
echo "Installed Go version ($INSTALLED_VERSION) doesn't match the expected version (go$VERSION)."
fi
else
echo "Go is not found in the PATH. Make sure to add Go's bin directory to your PATH."
fi
## Clean up
rm go$VERSION.linux-$ARCH.tar.gz