Skip to content

Commit

Permalink
build: detect GOPATH in direnv if not set systemwide
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Aug 30, 2023
1 parent caaabdc commit bca80a8
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
direnv_version_major=$(direnv version | cut -d "." -f1 | tr -d '\n')
direnv_version_minor=$(direnv version | cut -d "." -f2 | tr -d '\n')

if [[ $direnv_version_major -lt 2 ]] || [[ $direnv_version_major -eq 2 ]] && [[ $direnv_version_minor -lt 32 ]]; then
echo -e "\033[31munsupported direnv version $(direnv version) < 2.32.x"
exit 1
fi

if [[ "$SHELL" == "bash" ]]; then
if [ "${BASH_VERSINFO:-0}" -lt 4 ]; then
echo -e "\033[31mthe environment needs BASH 4 or above" >&2
exit 1
fi
fi

AP_ROOT=$(pwd)
export AP_ROOT

Expand All @@ -7,43 +22,61 @@ dotenv_if_exists dev.env
PATH_add "$AP_DEVCACHE_NODE_BIN"
PATH_add "$AP_DEVCACHE_BIN"

is_command() {
command -v "$1" >/dev/null
}

if ! has make ; then
echo "make is not installed"; exit 1
echo -e "\033[31mmake is not installed"; exit 1
fi

if ! has go ; then
echo "go is not installed"; exit 1
echo -e "\033[31mgo is not installed"; exit 1
fi

if ! has kind ; then
echo "kind is not installed. dev environment will try to install it"
fi

if ! has unzip ; then
echo "unzip is not installed"; exit 1
echo -e "\033[31munzip is not installed"; exit 1
fi

if ! has wget ; then
echo "wget is not installed"; exit 1
echo -e "\033[31mwget is not installed"; exit 1
fi

if ! has curl ; then
echo "curl is not installed"; exit 1
echo -e "\033[31mcurl is not installed"; exit 1
fi

if ! has npm ; then
echo "npm is not installed"; exit 1
echo -e "\033[31mnpm is not installed"; exit 1
fi

if ! has jq ; then
echo "jq is not installed"; exit 1
echo -e "\033[31mjq is not installed"; exit 1
fi

if ! has readlink ; then
echo "readlink is not installed"; exit 1
echo -e "\033[31mreadlink is not installed"; exit 1
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
if ! is_command brew; then
echo -e "\033[31mhomebrew is not installed. visit https://brew.sh"
exit 1
fi

if ! brew list gnu-getopt >/dev/null 2>&1 ; then
echo -e "\033[31mgnu-getopt is not installed. to install \"brew install gnu-getopt\""
exit 1
else
PATH_add "$(brew --prefix)/opt/gnu-getopt/bin"
fi
fi

if [ -z "$GOPATH" ]; then
if [[ -z "$GOPATH" ]]; then
GOPATH=$(go env GOPATH)
export GOPATH
fi
Expand Down

0 comments on commit bca80a8

Please sign in to comment.