-
Notifications
You must be signed in to change notification settings - Fork 18
/
goinstaller.sh
45 lines (39 loc) · 1.22 KB
/
goinstaller.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
#!/bin/bash
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
NC=`tput sgr0`
SHELL_TYPE=$(basename "$SHELL")
command_exists() {
command -v "$1" >/dev/null 2>&1
}
gowebsite=https://go.dev/dl/
golatest=$(curl -s https://go.dev/dl/ | grep -o '<a class="download downloadBox" href="[^"]*' | grep linux-amd64 | cut -d '"' -f 4 | cut -d / -f 3)
downloadgo=$gowebsite$golatest
goinstaller(){
echo "${YELLOW}[*] Installing GO ${NC}"
wget $downloadgo -P /tmp/
[ ! -d "/usr/local/go" ] && tar -C /usr/local/ -xzf /tmp/$golatest
rm /tmp/$golatest
echo $shellrc
echo 'export GOPATH=$HOME/go-workspace' >> $shellrc
echo 'export GOROOT=/usr/local/go' >> $shellrc
echo 'PATH=$PATH:$GOROOT/bin/:$GOPATH/bin' >> $shellrc
exec $SHELL
}
if ! command_exists go; then
if [ "$SHELL_TYPE" = "bash" ]; then
shellrc=~/.bashrc
echo $shellrc
goinstaller
command_exists go && echo -e "${GREEN}Go Installed Successfully !!!${NC}"
elif [ "$SHELL_TYPE" = "zsh" ]; then
shellrc=~/.zshrc
echo $shellrc
goinstaller
command_exists go && echo -e "${GREEN}Go Installed Successfully !!!${NC}"
else
echo "Unsupported shell type: $SHELL_TYPE"
fi
elif command_exists go; then
echo "${GREEN}[*] GO Already Installed ${NC}"
fi