forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doctor
executable file
·99 lines (87 loc) · 2.51 KB
/
doctor
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
#!/bin/bash
# Performs basic checks for tools required by Magic Modules.
# This must be in bash because no other tools are guaranteed to be present.
set -e
exitcode=0
if [ -t 1 ]; then
red=$'\e[1;31m'
grn=$'\e[1;32m'
yel=$'\e[1;33m'
blu=$'\e[1;34m'
mag=$'\e[1;35m'
cyn=$'\e[1;36m'
end=$'\e[0m'
else
red=''
grn=''
yel=''
blu=''
mag=''
cyn=''
end=''
fi
warn() {
printf "%s\n" "${!1}${2}${end}"
}
found=0
count_in_path() {
echo "Check for ${1} in path..."
found=$(which -a "${1}" | uniq | wc -l)
}
count_in_path ruby
if [ $found -eq 0 ] || ! ruby -e "exit Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.1.0')"; then
exitcode=1
warn "yel" " ruby version needs to be at least 3.1.0. See https://github.com/rbenv/rbenv for information on installing it."
else
warn "grn" " found!"
fi
count_in_path "go"
if [ $found -eq 0 ]; then
exitcode=1
warn "yel" " go not found. See https://golang.org/doc/install for information on installing it."
else
version=($(go version))
version=${version[2]}
if [[ "$version" < "go1.21.0" ]]; then
exitcode=1
warn "yel" " $version is installed, but go 1.21 or later is required. See https://golang.org/doc/install for information on installing it."
fi
if [[ -z "${GOPATH}" ]]; then
exitcode=1
warn "yel" " GOPATH is not set. Add 'export GOPATH=\$HOME/go' to your terminal's startup script and restart your terminal."
fi
if [ $exitcode -eq 0 ]; then
warn "grn" " found!"
fi
fi
count_in_path "goimports"
if [ $found -eq 0 ]; then
exitcode=1
warn "yel" " goimports not found. Run 'go install golang.org/x/tools/cmd/goimports@latest' to install it."
else
warn "grn" " found!"
fi
count_in_path "git"
if [ $found -eq 0 ]; then
exitcode=1
warn "yel" " git not found. See https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"
warn "yel" " for information on installing it."
else
warn "grn" " found!"
fi
count_in_path "terraform"
if [ $found -eq 0 ]; then
exitcode=1
warn "yel" " terraform not found. See https://learn.hashicorp.com/tutorials/terraform/install-cli"
warn "yel" " for information on installing it. Version 1.1.8 or later recommended."
else
warn "grn" " found!"
fi
count_in_path "make"
if [ $found -eq 0 ]; then
exitcode=1
warn "yel" " make not found. See https://www.gnu.org/software/make/ for information on downloading it."
else
warn "grn" " found!"
fi
exit $exitcode