git.iko.soy/typeable/oauth2-proxy
on v3.0.0 help sign in
140 lines 2.7 kB history raw
1#!/usr/bin/env bash
3RED='\033[0;31m'
4GREEN='\033[0;32m'
5BLUE='\033[0;34m'
6NC='\033[0m'
8declare -A tools=()
9declare -A desired=()
11for arg in "$@"; do
12 case ${arg%%=*} in
13 "--with-go")
14 desired[go]="${arg##*=}"
15 ;;
16 "--with-dep")
17 desired[dep]="${arg##*=}"
18 ;;
19 "--help")
20 printf "${GREEN}$0${NC}\n"
21 printf " available options:\n"
22 printf " --with-dep=${BLUE}<path_to_dep_binary>${NC}\n"
23 printf " --with-go=${BLUE}<path_to_go_binary>${NC}\n"
24 exit 0
25 ;;
26 *)
27 echo "Unknown option: $arg"
28 exit 2
29 ;;
30 esac
31done
33vercomp () {
34 if [[ $1 == $2 ]]
35 then
36 return 0
37 fi
38 local IFS=.
39 local i ver1=($1) ver2=($2)
40 # fill empty fields in ver1 with zeros
41 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
42 do
43 ver1[i]=0
44 done
45 for ((i=0; i<${#ver1[@]}; i++))
46 do
47 if [[ -z ${ver2[i]} ]]
48 then
49 # fill empty fields in ver2 with zeros
50 ver2[i]=0
51 fi
52 if ((10#${ver1[i]} > 10#${ver2[i]}))
53 then
54 return 1
55 fi
56 if ((10#${ver1[i]} < 10#${ver2[i]}))
57 then
58 return 2
59 fi
60 done
61 return 0
64check_for() {
65 echo -n "Checking for $1... "
66 if ! [ -z "${desired[$1]}" ]; then
67 TOOL_PATH="${desired[$1]}"
68 else
69 TOOL_PATH=$(command -v $1)
70 fi
71 if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then
72 printf "${RED}not found${NC}\n"
73 cd -
74 exit 1
75 else
76 printf "${GREEN}found${NC}\n"
77 tools[$1]=$TOOL_PATH
78 fi
81check_go_version() {
82 echo -n "Checking go version... "
83 GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+\.[0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}')
84 vercomp $GO_VERSION 1.9
85 case $? in
86 0) ;&
87 1)
88 printf "${GREEN}"
89 echo $GO_VERSION
90 printf "${NC}"
91 ;;
92 2)
93 printf "${RED}"
94 echo "$GO_VERSION < 1.9"
95 exit 1
96 ;;
97 esac
98 VERSION=$(${tools[go]} version | ${tools[awk]} '{print $3}')
99 tools["go_version"]="${VERSION}"
102check_docker_version() {
103 echo -n "Checking docker version... "
104 DOCKER_VERSION=$(${tools[docker]} version | ${tools[awk]})
107check_go_env() {
108 echo -n "Checking \$GOPATH... "
109 if [ -z "$GOPATH" ]; then
110 printf "${RED}invalid${NC} - GOPATH not set\n"
111 exit 1
112 fi
113 printf "${GREEN}valid${NC} - $GOPATH\n"
116cd ${0%/*}
118if [ ! -f .env ]; then
119 rm .env
120fi
122check_for make
123check_for awk
124check_for go
125check_go_version
126check_go_env
127check_for dep
129echo
131cat <<- EOF > .env
132 MAKE := "${tools[make]}"
133 GO := "${tools[go]}"
134 GO_VERSION := ${tools[go_version]}
135 DEP := "${tools[dep]}"
136EOF
138echo "Environment configuration written to .env"
140cd - > /dev/null