Skip to content

Instantly share code, notes, and snippets.

@cyb3rsalih
Last active January 4, 2022 21:32
Show Gist options
  • Select an option

  • Save cyb3rsalih/354bda3a923bcf9ae4ae8e49f93462a0 to your computer and use it in GitHub Desktop.

Select an option

Save cyb3rsalih/354bda3a923bcf9ae4ae8e49f93462a0 to your computer and use it in GitHub Desktop.
Download Go and Install - Linux
#!/bin/bash
#Download GO and install it
curl=$(which curl)
outfile="output.txt"
base_url="https://go.dev"
download="dl"
url="$base_url/$download/"
function dump_webpage() {
$curl -o $outfile $url -s
check_errors
}
function strip_html() {
grep "download downloadBox" $outfile | grep "/dl.*\"" -o | sed 's/"//g' > temp.txt
echo "GETTING URL OK"
curl -L "$base_url$(cat temp.txt|sed -n 3p)" -o go.tar.gz -s > /dev/null
echo "DOWNLOAD OK"
rm temp.txt
rm $outfile
check_errors
sudo tar -xvf go.tar.gz > /dev/null
echo "ARCHIVE EXTRACT OK"
sudo mv go /usr/local > /dev/null
echo "MOVE TO /usr/local OK"
echo "export GOROOT=/usr/local/go" >> ~/.$(echo $SHELL|sed "s/\/bin\///g")rc
echo "export GOPATH=$HOME/go" >> ~/.$(echo $SHELL|sed "s/\/bin\///g")rc
echo 'export PATH=/usr/local/go/bin/:$HOME/go/bin/:$PATH' >> ~/.$(echo $SHELL|sed "s/\/bin\///g")rc
echo "ALIAS SET OK"
sleep 1
cd ~/
pwd
source .$(echo $SHELL|sed "s/\/bin\///g")rc
echo .$(echo $SHELL|sed "s/\/bin\///g")rc
echo "source OK"
echo "VERIFYING..."
go version
echo "READY!"
}
function check_errors() {
[ $? -ne 0 ] && echo "Error Downloading Page..." && exit -1
}
dump_webpage
strip_html
# I don't know why, but adding to path doesn't work. Please add to path manually and $source .bashrc | .zshrc THANKS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment