git.iko.soy/typeable/oauth2-proxy
on v4.1.0 help sign in
139 lines 2.8 kB history raw
1#!/usr/bin/env bash
3RED='\033[0;31m'
4GREEN='\033[0;32m'
5BLUE='\033[0;34m'
6NC='\033[0m'
8if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then
9 echo "This script requires Bash version >= 4"; exit 1;
10fi
12declare -A tools=()
13declare -A desired=()
15for arg in "$@"; do
16 case ${arg%%=*} in
17 "--with-go")
18 desired[go]="${arg##*=}"
19 ;;
20 "--help")
21 printf "${GREEN}$0${NC}\n"
22 printf " available options:\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.12
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.12"
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 GOPATH="$(go env GOPATH)"
110 if [ -z "$GOPATH" ]; then
111 printf "${RED}invalid${NC} - GOPATH not set\n"
112 exit 1
113 fi
114 printf "${GREEN}valid${NC} - $GOPATH\n"
117cd ${0%/*}
119rm -fv .env
121check_for make
122check_for awk
123check_for go
124check_go_version
125check_go_env
126check_for golangci-lint
128echo
130cat <<- EOF > .env
131 MAKE := "${tools[make]}"
132 GO := "${tools[go]}"
133 GO_VERSION := ${tools[go_version]}
134 GOLANGCILINT := "${tools[golangci-lint]}"
135EOF
137echo "Environment configuration written to .env"
139cd - > /dev/null