Last active
August 25, 2017 02:38
-
-
Save rafaelhenrique/f3f7c5c50b9c426ce1f9 to your computer and use it in GitHub Desktop.
Setting environment to use Golang (after golang install)
This file contains 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
#!/bin/bash | |
SCRIPT=`basename ${BASH_SOURCE[0]}` | |
NORM=`tput sgr0` | |
BOLD=`tput bold` | |
REV=`tput smso` | |
GODIR="/usr/local/go" | |
GOBINDIR="$GODIR/bin" | |
if [ ! -d $GODIR -o ! -d $GOBINDIR ]; then | |
echo "Go needs be installed on /usr/local/go" | |
exit 1 | |
fi | |
function USE { | |
echo -e "${REV}Basic usage:${NORM} ${BOLD}$SCRIPT -w work_directory ${NORM}"\\n | |
echo "${REV}-w${NORM} write your go directory workspace" | |
echo -e "${REV}-h${NORM} Displays this help message."\\n | |
echo -e "Example: ${BOLD}$SCRIPT -w /home/rafael/work ${NORM}"\\n | |
exit 1 | |
} | |
function CREATE_DIR { | |
echo "Creating structure of directories..." | |
mkdir -p "$1/src/github.com" | |
} | |
function CREATE_ENV { | |
echo "Writing env variables on .bashrc..." | |
cat >> ~/.bashrc <<EOF | |
# Golang env | |
export PATH=\$PATH:$GOBINDIR:$1 | |
export GOPATH=$1 | |
export GOROOT="$GODIR" | |
EOF | |
export PATH="$PATH:$GOBINDIR:$1" | |
export GOPATH="$1" | |
export GOROOT="$GODIR" | |
} | |
function GET_FIRST_PROJECT { | |
go get github.com/golang/example/hello | |
} | |
NUMARGS=$# | |
if [ $NUMARGS -lt 1 ]; then | |
USE | |
fi | |
options=':w' | |
while getopts $options ARGM; do | |
case $ARGM in | |
w) | |
WORKSPACE=$2 | |
;; | |
h) | |
USE | |
;; | |
\?) | |
echo -e \\n"Option -${BOLD}$OPTARG${NORM} not allowed." | |
USE | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
CREATE_ENV $WORKSPACE | |
CREATE_DIR $WORKSPACE | |
GET_FIRST_PROJECT | |
echo "Finish please run this command: source ~/.bashrc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment