forked from wave-k8s/wave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·182 lines (167 loc) · 3.95 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env bash
if (( ${BASH_VERSION:0:1} < 4 )); then
echo "This configure script requires at least Bash 4"
if [[ "$OSTYPE" == darwin* ]]; then
echo "On macOS, you can upgrade it using Homebrew <https://brew.sh/> by typing: brew install bash"
fi
exit 1
fi
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
declare -A tools=()
declare -A desired=()
for arg in "$@"; do
case ${arg%%=*} in
"--with-go")
desired[go]="${arg##*=}"
;;
"--with-dep")
desired[dep]="${arg##*=}"
;;
"--with-kubectl")
desired[kubectl]="${arg##*=}"
;;
"--with-kustomize")
desired[kustomize]="${arg##*=}"
;;
"--with-kubebuilder")
desired[kubebuilder]="${arg##*=}"
;;
"--help")
printf "${GREEN}$0${NC}\n"
printf " available options:\n"
printf " --with-dep=${BLUE}<path_to_dep_binary>${NC}\n"
printf " --with-go=${BLUE}<path_to_go_binary>${NC}\n"
printf " --with-kubectl=${BLUE}<path_to_kubectl>${NC}\n"
printf " --with-kustomize=${BLUE}<path_to_kustomize>${NC}\n"
printf " --with-kubebuilder=${BLUE}<path_to_kubebuilder_folder>${NC}\n"
exit 0
;;
*)
echo "Unknown option: $arg"
exit 2
;;
esac
done
vercomp () {
if [[ $1 == $2 ]]
then
return 0
fi
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
check_go_version() {
echo -n "Checking go version... "
GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+[\.0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}')
vercomp $GO_VERSION 1.10
case $? in
0) ;&
1)
printf "${GREEN}"
echo $GO_VERSION
printf "${NC}"
;;
2)
printf "${RED}"
echo "$GO_VERSION < 1.10"
exit 1
;;
esac
}
check_for() {
echo -n "Checking for $1... "
if ! [ -z "${desired[$1]}" ]; then
TOOL_PATH="${desired[$1]}"
else
TOOL_PATH=$(command -v $1)
fi
if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then
printf "${RED}not found${NC}\n"
cd - > /dev/null
exit 1
else
printf "${GREEN}found${NC}\n"
tools[$1]=$TOOL_PATH
fi
}
check_go_env() {
echo -n "Checking \$GOPATH... "
if [ -z "$GOPATH" ]; then
printf "${RED}invalid${NC} - GOPATH not set\n"
exit 1
fi
printf "${GREEN}valid${NC} - $GOPATH\n"
}
check_kubebuilder() {
echo -n "Checking for kubebuilder... "
if ! [ -z "${desired[kubebuilder]}" ]; then
TOOL_PATH="${desired[kubebuilder]}"
else
TOOL_PATH=$(command -v kubebuilder | sed s/\\/kubebuilder$//)
fi
if ! [ -d "$TOOL_PATH" -a -f "$TOOL_PATH/kubebuilder" -a -x "$TOOL_PATH/kubebuilder" ]; then
printf "${RED}not found${NC}\n"
cd - > /dev/null
exit 1
else
printf "${GREEN}found${NC} - using $TOOL_PATH\n"
tools[kubebuilder]=$TOOL_PATH
fi
}
cd ${0%/*}
check_for make
check_for awk
check_for sed
check_for shasum
check_for tar
check_for go
check_for dep
check_for ginkgo
check_for golangci-lint
check_kubebuilder
check_go_version
check_go_env
check_for kustomize
export PATH="${tools[kubebuilder]};$PATH"
check_for kubectl
cat <<- EOF > .env
MAKE := ${tools[make]}
SED := ${tools[sed]}
SHASUM := ${tools[shasum]}
TAR := ${tools[tar]}
GO := ${tools[go]}
GOVERSION := $GO_VERSION
GINKGO := ${tools[ginkgo]}
DEP := ${tools[dep]}
LINTER := ${tools[golangci-lint]}
KUBECTL := ${tools[kubectl]}
KUSTOMIZE := ${tools[kustomize]}
KUBEBUILDER := ${tools[kubebuilder]}
EOF
echo "Environment configuration written to .env"
cd - > /dev/null