This repository has been archived on 2024-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
thelinuxlist/scripts/goinstall.sh

44 lines
1.3 KiB
Bash

#!/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
done
# Check if curl is installed
if [ ! -x /usr/bin/curl ] ; then
CURL_NOT_EXIST=1
apt install -y curl
else
CURL_NOT_EXIST=0
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
export PATH=$PATH:/usr/local/go/bin
cd ~