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 #!/bin/bash
# set version, check: https://github.com/golang/go/releases # command info
goVersion="1.13.3" 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 source /mnt/hdd/raspiblitz.conf
isARM=$(uname -m | grep -c 'arm')
isAARCH64=$(uname -m | grep -c 'aarch64')
isX86_64=$(uname -m | grep -c 'x86_64')
# 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 # switch on
source /etc/profile if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "Check Framework: Go" # set version, check: https://github.com/golang/go/releases
goInstalled=$(go version 2>/dev/null | grep -c 'go') goVersion="1.13.3"
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
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 # make sure go is installed
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 # get Go vars - needed if there was no log-out since Go installed
go env -w GOPATH=/usr/local/gocode source /etc/profile
echo "Check Framework: Go"
goInstalled=$(go version 2>/dev/null | grep -c 'go') goInstalled=$(go version 2>/dev/null | grep -c 'go')
fi if [ ${goInstalled} -eq 0 ];then
if [ ${goInstalled} -eq 0 ];then if [ ${isARM} -eq 1 ] ; then
echo "FAIL: Was not able to install Go" goOSversion="armv6l"
sleep 4 fi
exit 1 if [ ${isAARCH64} -eq 1 ] ; then
fi goOSversion="arm64"
fi
if [ ${isX86_64} -eq 1 ] ; then
goOSversion="amd64"
fi
correctGoVersion=$(go version | grep -c "go${goVersion}") echo "*** Installing Go v${goVersion} for ${goOSversion} ***"
if [ ${correctGoVersion} -eq 0 ]; then
echo "WARNING: You work with an untested version of GO - should be ${goVersion} .. trying to continue" # wget https://storage.googleapis.com/golang/go${goVersion}.linux-${goOSversion}.tar.gz
go version cd /home/admin/download
sleep 3 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 ""
echo "Installed $(go version)"
echo ""
exit 0
fi fi
echo "" # switch off
echo "Installed $(go version)" if [ "$1" = "0" ] || [ "$1" = "off" ]; then
echo "" # 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 if [ $isInstalled -eq 0 ] || [ "$1" == "update" ]; then
echo "# Installing lndconnect.." echo "# Installing lndconnect.."
# make sure Go is installed # make sure Go is installed
/home/admin/config.scripts/bonus.go.sh /home/admin/config.scripts/bonus.go.sh on
# get Go vars # get Go vars
source /etc/profile source /etc/profile
# Install latest lndconnect from source: # 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') isInstalled=$(sudo ls /etc/systemd/system/loopd.service 2>/dev/null | grep -c 'loopd.service')
if [ ${isInstalled} -eq 0 ]; then if [ ${isInstalled} -eq 0 ]; then
/home/admin/config.scripts/bonus.go.sh /home/admin/config.scripts/bonus.go.sh on
# get Go vars # get Go vars
source /etc/profile source /etc/profile

View file

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