Merge pull request #1293 from openoms/go-uninstall

add Go uninstall option
This commit is contained in:
Christian Rotzoll 2020-06-26 13:35:07 +02:00 committed by GitHub
commit e4a987f402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 99 additions and 65 deletions

View file

@ -1,76 +1,110 @@
#!/bin/bash
# set version, check: https://github.com/golang/go/releases
goVersion="1.13.3"
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "config script to install Go"
echo "bonus.go.sh [on|off]"
exit 1
fi
# get cpu architecture
isARM=$(uname -m | grep -c 'arm')
isAARCH64=$(uname -m | grep -c 'aarch64')
isX86_64=$(uname -m | grep -c 'x86_64')
source /mnt/hdd/raspiblitz.conf
# make sure go is installed
# add default value to raspi config if needed
if ! grep -Eq "^golang=" /mnt/hdd/raspiblitz.conf; then
echo "golang=off" >> /mnt/hdd/raspiblitz.conf
fi
# get Go vars - needed if there was no log-out since Go installed
source /etc/profile
# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "Check Framework: Go"
goInstalled=$(go version 2>/dev/null | grep -c 'go')
if [ ${goInstalled} -eq 0 ];then
if [ ${isARM} -eq 1 ] ; then
goOSversion="armv6l"
fi
if [ ${isAARCH64} -eq 1 ] ; then
goOSversion="arm64"
fi
if [ ${isX86_64} -eq 1 ] ; then
goOSversion="amd64"
fi
# set version, check: https://github.com/golang/go/releases
goVersion="1.13.3"
echo "*** Installing Go v${goVersion} for ${goOSversion} ***"
# get cpu architecture
isARM=$(uname -m | grep -c 'arm')
isAARCH64=$(uname -m | grep -c 'aarch64')
isX86_64=$(uname -m | grep -c 'x86_64')
# wget https://storage.googleapis.com/golang/go${goVersion}.linux-${goOSversion}.tar.gz
cd /home/admin/download
wget https://dl.google.com/go/go${goVersion}.linux-${goOSversion}.tar.gz
if [ ! -f "./go${goVersion}.linux-${goOSversion}.tar.gz" ]
then
echo "!!! FAIL !!! Download not success."
rm -f go${goVersion}.linux-${goOSversion}.tar.gz*
exit 1
fi
sudo tar -C /usr/local -xzf go${goVersion}.linux-${goOSversion}.tar.gz
rm -f go${goVersion}.linux-${goOSversion}.tar.gz*
sudo mkdir /usr/local/gocode
sudo chmod 777 /usr/local/gocode
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/usr/local/gocode
export PATH=$PATH:$GOPATH/bin
if [ $(cat /etc/profile | grep -c "GOROOT=") -eq 0 ]; then
sudo bash -c "echo 'GOROOT=/usr/local/go' >> /etc/profile"
sudo bash -c "echo 'PATH=\$PATH:\$GOROOT/bin/' >> /etc/profile"
sudo bash -c "echo 'GOPATH=/usr/local/gocode' >> /etc/profile"
sudo bash -c "echo 'PATH=\$PATH:\$GOPATH/bin/' >> /etc/profile"
fi
# make sure go is installed
# set GOPATH https://github.com/golang/go/wiki/SettingGOPATH
go env -w GOPATH=/usr/local/gocode
# get Go vars - needed if there was no log-out since Go installed
source /etc/profile
echo "Check Framework: Go"
goInstalled=$(go version 2>/dev/null | grep -c 'go')
fi
if [ ${goInstalled} -eq 0 ];then
echo "FAIL: Was not able to install Go"
sleep 4
exit 1
fi
if [ ${goInstalled} -eq 0 ];then
if [ ${isARM} -eq 1 ] ; then
goOSversion="armv6l"
fi
if [ ${isAARCH64} -eq 1 ] ; then
goOSversion="arm64"
fi
if [ ${isX86_64} -eq 1 ] ; then
goOSversion="amd64"
fi
correctGoVersion=$(go version | grep -c "go${goVersion}")
if [ ${correctGoVersion} -eq 0 ]; then
echo "WARNING: You work with an untested version of GO - should be ${goVersion} .. trying to continue"
go version
sleep 3
echo "*** Installing Go v${goVersion} for ${goOSversion} ***"
# wget https://storage.googleapis.com/golang/go${goVersion}.linux-${goOSversion}.tar.gz
cd /home/admin/download
wget https://dl.google.com/go/go${goVersion}.linux-${goOSversion}.tar.gz
if [ ! -f "./go${goVersion}.linux-${goOSversion}.tar.gz" ]
then
echo "!!! FAIL !!! Download not success."
rm -f go${goVersion}.linux-${goOSversion}.tar.gz*
exit 1
fi
sudo tar -C /usr/local -xzf go${goVersion}.linux-${goOSversion}.tar.gz
rm -f go${goVersion}.linux-${goOSversion}.tar.gz*
sudo mkdir /usr/local/gocode
sudo chmod 777 /usr/local/gocode
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/usr/local/gocode
export PATH=$PATH:$GOPATH/bin
if [ $(cat /etc/profile | grep -c "GOROOT=") -eq 0 ]; then
sudo bash -c "echo 'GOROOT=/usr/local/go' >> /etc/profile"
sudo bash -c "echo 'PATH=\$PATH:\$GOROOT/bin/' >> /etc/profile"
sudo bash -c "echo 'GOPATH=/usr/local/gocode' >> /etc/profile"
sudo bash -c "echo 'PATH=\$PATH:\$GOPATH/bin/' >> /etc/profile"
fi
# set GOPATH https://github.com/golang/go/wiki/SettingGOPATH
go env -w GOPATH=/usr/local/gocode
goInstalled=$(go version 2>/dev/null | grep -c 'go')
fi
if [ ${goInstalled} -eq 0 ];then
echo "FAIL: Was not able to install Go"
sleep 4
exit 1
fi
correctGoVersion=$(go version | grep -c "go${goVersion}")
if [ ${correctGoVersion} -eq 0 ]; then
echo "WARNING: You work with an untested version of GO - should be ${goVersion} .. trying to continue"
go version
sleep 3
echo ""
fi
# setting value in raspi blitz config
sudo sed -i "s/^golang=.*/golang=on/g" /mnt/hdd/raspiblitz.conf
echo ""
echo "Installed $(go version)"
echo ""
exit 0
fi
echo ""
echo "Installed $(go version)"
echo ""
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# setting value in raspiblitz config
sudo sed -i "s/^golang=.*/golang=off/g" /mnt/hdd/raspiblitz.conf
echo "*** REMOVING GO ***"
sudo rm -rf /usr/local/go
echo "OK Go removed."
exit 0
fi
echo "FAIL - Unknown Parameter $1"
exit 1

View file

@ -33,7 +33,7 @@ isInstalled=$(lndconnect -h 2>/dev/null | grep "nocert" -c)
if [ $isInstalled -eq 0 ] || [ "$1" == "update" ]; then
echo "# Installing lndconnect.."
# make sure Go is installed
/home/admin/config.scripts/bonus.go.sh
/home/admin/config.scripts/bonus.go.sh on
# get Go vars
source /etc/profile
# Install latest lndconnect from source:

View file

@ -33,7 +33,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
isInstalled=$(sudo ls /etc/systemd/system/loopd.service 2>/dev/null | grep -c 'loopd.service')
if [ ${isInstalled} -eq 0 ]; then
/home/admin/config.scripts/bonus.go.sh
/home/admin/config.scripts/bonus.go.sh on
# get Go vars
source /etc/profile

View file

@ -1,7 +1,7 @@
#!/bin/bash
# command info
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "small config script to install NodeJs"
echo "bonus.nodejs.sh [on|off]"
exit 1