From 872089cd9cb06e56016da0e976b77e28af37de29 Mon Sep 17 00:00:00 2001 From: Molluk Date: Fri, 29 Sep 2017 13:12:26 -0700 Subject: [PATCH] Added: goup.sh: get latest version of golang --- goup.sh | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 goup.sh diff --git a/goup.sh b/goup.sh new file mode 100755 index 0000000..f4617f3 --- /dev/null +++ b/goup.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +case ${1} in + + --set-version) + version="${2}" + ;; + + *) + pkgname="go" + version="1.9" + distfile="https://storage.googleapis.com/golang/${pkgname}${version}.linux-amd64.tar.gz" + tmpdir="/tmp" + installdir="/usr/local" + checksum=d70eadefce8e160638a9a6db97f7192d8463069ab33138893ad3bf31b0650a79 + + # Colors + RED='\033[0;31m' + LRED="\033[1;31m" + BLUE="\033[0;34m" + LBLUE="\033[1;34m" + GREEN="\033[0;32m" + LGREEN="\033[1;32m" + YELLOW="\033[1;33m" + CYAN="\033[0;36m" + LCYAN="\033[1;36m" + PURPLE="\033[0;35m" + LPURPLE="\033[1;35m" + BWHITE="\e[1m" + NC='\033[0m' # No Color + + + fetch_(){ + printf "${BWHITE}\nFetching file\n${NC}" + cd ${tmpdir} + + if [ ! -f ${pkgname}${version}.linux-amd64.tar.gz ];then + wget ${distfile} + fi + printf "${BWHITE}\nVerifying checksum\n${NC}" + + if [ ! -f checksum.txt ];then + echo "${checksum} ${pkgname}${version}.linux-amd64.tar.gz" >> checksum.txt + sha256sum -c checksum.txt + + else + sha256sum -c checksum.txt + fi + + if [ $? = 1 ];then + exit 0; + fi + } + + extract-install_(){ + cd ${tmpdir} + + if [ ! -f ${pkgname}${version}.linux-amd64.tar.gz ];then + echo "No file found to extract" + else + printf "${BWHITE}\nExtracting and installing to:${NC} " && printf "${LCYAN}${installdir}\n${NC}" + printf "${LRED}\nAuthentication for root:${NC}\n" && su -c "tar -C ${installdir} -xzvf ${pkgname}${version}.linux-amd64.tar.gz" + fi + + if [ ! -d /usr/local/go ];then + echo -e "\nCan not find ${pkgname} in ${installdir}\n" + exit 0; + else + echo -e "${LGREEN}\n${pkgname}-${version} has been installed to ${installdir}${NC}" + fi + } + + add-path_(){ + echo -e "\n1. Add gopath to ${HOME}/.profile\n" + echo -e "\n2. Add gopath to ${HOME}/.bashrc\n" + read choice + + if [ "${choice}" = "1" ];then + echo 'export PATH=$PATH:/usr/local/go/bin' >> ${HOME}/.profile + elif [ "${choice}" = "2" ];then + printf "${BWHITE}\nAdding gopath to .bashrc${NC}" + echo 'export PATH=$PATH:/usr/local/go/bin' >> ${HOME}/.bashrc + catpath=$(cat ${HOME}/.bashrc | grep /usr/local/go/bin) + + ${catpath} + + if [ $? = 1 ];then + printf "${BWHITE}\n\nRunning grep on .bashrc\n\n${NC}" + printf "${LCYAN}Grep Results:${NC} ${LGREEN}${catpath}\n\n${NC}" + + printf "${YELLOW}Please edit: ${HOME}/.bashrc:${NC}\n\n" + printf "${YELLOW}Above are results for grep on .bashrc, if nothing is there then please add:\n\n${NC}${BWHITE}" + echo -e 'export PATH=$PATH:/usr/local/go/bin' && printf "\n\n${NC}" + + else + printf "${LGREEN}\n\ngo has been added to your path in ${HOME}/.bashrc\n\n${NC}" + fi + fi + } + fetch_ + extract-install_ + add-path_ + ;; + + --help | -h) + printf "${BWHITE}\nUseage ${0} [options] [arguments]\n\n${NC}" + + printf "--set-version enter in an existing go version to download\n" + printf "--help, -help Display this help page" + ;; + +esac \ No newline at end of file