Last active
April 19, 2016 12:25
-
-
Save undirectlookable/f89a9df8628957b148b6 to your computer and use it in GitHub Desktop.
Install Go Binaries on Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Install Go Binaries on any ARMv6/ARMv7 system. | |
# Binaries from http://dave.cheney.net/unofficial-arm-tarballs | |
# Fetch release page and get latest tarball link | |
LINK=`wget -q -O - https://golang.org/dl/ | grep '\/go.*linux-armv6l\.tar\.gz' | head -1 | sed 's/^\(.*\)\(http[^">]*\)\(.*\)$/\2/'` | |
# Get Filename | |
FILENAME=`echo $LINK | sed 's/\(.*\)\(go.*linux-armv6l\.tar\.gz\)/\2/'` | |
# Download | |
if [ -f $FILENAME ]; then | |
echo "File $FILENAME exists, skip download." | |
else | |
echo "Downloading $LINK" | |
wget $LINK | |
fi | |
# Backup old files | |
if [ -d /usr/local/go ]; then | |
[ -d /usr/local/go-old ] && rm -rf /usr/local/go-old | |
mv /usr/local/go /usr/local/go-old | |
echo "Your old go has moved to /usr/local/go-old" | |
fi | |
# Install | |
echo "Intalling..." | |
tar -zxf $FILENAME -C /usr/local | |
# Add env | |
echo "Adding environment variables" | |
PFDIR=/etc/profile.d | |
if [ ! -d $PFDIR ]; then | |
mkdir -p $PFDIR | |
fi | |
if [ -f $PFDIR/goenv.sh ]; then | |
rm $PFDIR/goenv.sh | |
fi | |
GOENV1="export GOROOT=/usr/local/go" | |
GOENV2="export PATH=\$PATH:\$GOROOT/bin" | |
eval $GOENV1 | |
eval $GOENV2 | |
echo "$GOENV1 | |
$GOENV2" >> $PFDIR/goenv.sh | |
# Finish | |
echo "Done" | |
echo `go version` | |
echo " " | |
echo "If you cannot run go command, check GOROOT=/usr/local/go in your env, and \$GOROOT/bin in your PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment