forked from Sophia/thelinuxlist
EOL this project :(
This commit is contained in:
@ -1,44 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
trap 'exit 130' INT
|
||||
while true
|
||||
do
|
||||
read -r -p "Would you like to install Go Language? [Y/n] " input
|
||||
|
||||
case $input in
|
||||
[yY][eE][sS]|[yY])
|
||||
break
|
||||
;;
|
||||
[nN][oO]|[nN])
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "That wasn't an option..."
|
||||
;;
|
||||
esac
|
||||
|
||||
# Confirmation prompt
|
||||
while true; do
|
||||
read -r -p "Would you like to install Go Language? [Y/n] " input
|
||||
|
||||
case $input in
|
||||
[yY][eE][sS]|[yY])
|
||||
break
|
||||
;;
|
||||
[nN][oO]|[nN])
|
||||
echo "Go installation aborted."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "That wasn't an option..."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if curl is installed
|
||||
if [ ! -x /usr/bin/curl ] ; then
|
||||
CURL_NOT_EXIST=1
|
||||
apt install -y curl
|
||||
if ! command -v curl &>/dev/null; then
|
||||
echo "curl is required but not installed. Installing curl..."
|
||||
sudo apt update && sudo apt install -y curl
|
||||
fi
|
||||
|
||||
# Get latest Go version
|
||||
if [ "$(uname -m)" == "x86_64" ]; then
|
||||
ARCH="amd64"
|
||||
elif [ "$(uname -m)" == "armv6l" ]; then
|
||||
ARCH="armv6l"
|
||||
else
|
||||
CURL_NOT_EXIST=0
|
||||
ARCH="386"
|
||||
fi
|
||||
apt remove golang -y
|
||||
rm -rf /tmp/go/
|
||||
mkdir /tmp/go/
|
||||
cd /tmp/go/
|
||||
VER=$(curl --silent "https://go.dev/dl/?mode=json" | grep '"version":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's|[v,]||g' | head -1)
|
||||
if [ -n "$(uname -a | grep x86_64)" ]; then
|
||||
curl -fsSL -o "/tmp/go/"$VER".linux-amd64.tar.gz" "https://go.dev/dl/"$VER".linux-amd64.tar.gz"
|
||||
fi
|
||||
if [ -n "$(uname -a | grep armv6l)" ]; then
|
||||
curl -fsSL -o "/tmp/go/"$VER".linux-armv6l.tar.gz" "https://go.dev/dl/"$VER".linux-armv6l.tar.gz"
|
||||
fi
|
||||
if [ -n "$(uname -a | grep i386)" ]; then
|
||||
curl -fsSL -o "/tmp/go/"$VER".linux-386.tar.gz" "https://go.dev/dl/"$VER".linux-386.tar.gz"
|
||||
fi
|
||||
rm -rf /usr/local/go && tar -C /usr/local -xzf *.tar.gz
|
||||
chmod +x /usr/local/go/bin/go
|
||||
|
||||
GO_VERSION=$(curl -sSL https://golang.org/dl/?mode=json | grep -oP '"version":"\K[^"]+' | head -n1)
|
||||
GO_URL="https://golang.org/dl/go$GO_VERSION.linux-$ARCH.tar.gz"
|
||||
|
||||
# Install Go
|
||||
echo "Downloading and installing Go $GO_VERSION..."
|
||||
curl -fsSL -o "/tmp/go.tar.gz" "$GO_URL"
|
||||
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf /tmp/go.tar.gz
|
||||
rm -f /tmp/go.tar.gz
|
||||
|
||||
# Update PATH
|
||||
echo "Updating PATH..."
|
||||
export PATH=$PATH:/usr/local/go/bin
|
||||
cd ~
|
||||
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc # Add to .bashrc for persistent PATH
|
||||
|
||||
echo "Go $GO_VERSION has been successfully installed."
|
||||
|
Reference in New Issue
Block a user