This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
tools.sh
executable file
·311 lines (241 loc) · 9.15 KB
/
tools.sh
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/bash
# version
DATE=
KUBECTL=
KOPS=
HELM=
DRAFT=
GUARD=
mkdir -p ~/.kops-cui
CONFIG=~/.kops-cui/tools
touch ${CONFIG} && . ${CONFIG}
################################################################################
command -v tput > /dev/null && TPUT=true
_echo() {
if [ "${TPUT}" != "" ] && [ "$2" != "" ]; then
echo -e "$(tput setaf $2)$1$(tput sgr0)"
else
echo -e "$1"
fi
}
_result() {
_echo "# $@" 4
}
_command() {
_echo "$ $@" 3
}
_success() {
_echo "+ $@" 2
exit 0
}
_error() {
_echo "- $@" 1
exit 1
}
DATE=$(date '+%Y-%m-%d %H:%M:%S')
OS_NAME="$(uname | awk '{print tolower($0)}')"
OS_FULL="$(uname -a)"
OS_TYPE=
if [ "${OS_NAME}" == "linux" ]; then
if [ $(echo "${OS_FULL}" | grep -c "amzn1") -gt 0 ]; then
OS_TYPE="yum"
elif [ $(echo "${OS_FULL}" | grep -c "amzn2") -gt 0 ]; then
OS_TYPE="yum"
elif [ $(echo "${OS_FULL}" | grep -c "el6") -gt 0 ]; then
OS_TYPE="yum"
elif [ $(echo "${OS_FULL}" | grep -c "el7") -gt 0 ]; then
OS_TYPE="yum"
elif [ $(echo "${OS_FULL}" | grep -c "Ubuntu") -gt 0 ]; then
OS_TYPE="apt"
elif [ $(echo "${OS_FULL}" | grep -c "coreos") -gt 0 ]; then
OS_TYPE="apt"
fi
elif [ "${OS_NAME}" == "darwin" ]; then
OS_TYPE="brew"
fi
_result "${OS_NAME} [${OS_TYPE}]"
_result "${DATE}"
if [ "${OS_TYPE}" == "" ]; then
_error "Not supported OS. [${OS_NAME}]"
fi
# brew for mac
if [ "${OS_TYPE}" == "brew" ]; then
command -v brew > /dev/null || ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
# for ubuntu
if [ "${OS_TYPE}" == "apt" ]; then
export LC_ALL=C
fi
# ssh keygen
[ ! -f ~/.ssh/id_rsa ] && ssh-keygen -q -f ~/.ssh/id_rsa -N ''
# update
echo "================================================================================"
_result "update..."
if [ "${OS_TYPE}" == "apt" ]; then
sudo apt update && sudo apt upgrade -y
command -v jq > /dev/null || sudo apt install -y jq
command -v git > /dev/null || sudo apt install -y git
command -v pip > /dev/null || sudo apt install -y python3-pip
command -v ab > /dev/null || sudo apt install -y apache2-utils
elif [ "${OS_TYPE}" == "yum" ]; then
sudo yum update -y
command -v jq > /dev/null || sudo yum install -y jq
command -v git > /dev/null || sudo yum install -y git
command -v pip > /dev/null || sudo yum install -y python3-pip
command -v ab > /dev/null || sudo yum install -y httpd-tools
elif [ "${OS_TYPE}" == "brew" ]; then
brew update && brew upgrade
command -v jq > /dev/null || brew install jq
command -v git > /dev/null || brew install git
command -v fzf > /dev/null || brew install fzf
# getopt
GETOPT=$(getopt 2>&1 | head -1 | xargs)
if [ "${GETOPT}" == "--" ]; then
brew install gnu-getopt
brew link --force gnu-getopt
fi
fi
# aws-cli
echo "================================================================================"
_result "install aws-cli..."
if [ "${OS_TYPE}" == "brew" ]; then
command -v aws > /dev/null || brew install awscli
else
pip3 install --upgrade awscli
fi
aws --version | xargs
if [ ! -f ~/.aws/config ]; then
# aws region
aws configure set default.region ap-northeast-2
fi
# kubectl
echo "================================================================================"
_result "install kubectl..."
if [ "${OS_TYPE}" == "brew" ]; then
command -v kubectl > /dev/null || brew install kubernetes-cli
else
VERSION=$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
if [ "${KUBECTL}" != "${VERSION}" ] || [ "$(command -v kubectl)" == "" ]; then
_result " ${KUBECTL} >> ${VERSION}"
curl -LO https://storage.googleapis.com/kubernetes-release/release/${VERSION}/bin/${OS_NAME}/amd64/kubectl
chmod +x kubectl && sudo mv kubectl /usr/local/bin/kubectl
KUBECTL="${VERSION}"
fi
fi
kubectl version --client --short | xargs | awk '{print $3}'
# terraform
echo "================================================================================"
_result "install terraform..."
if [ "${OS_TYPE}" == "brew" ]; then
command -v terraform > /dev/null || brew install terraform
else
VERSION=$(curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | jq -r '.tag_name' | cut -d'v' -f2)
if [ "${TERRAFORM}" != "${VERSION}" ] || [ "$(command -v terraform)" == "" ]; then
_result " ${TERRAFORM} >> ${VERSION}"
curl -LO "https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_${OS_NAME}_amd64.zip"
apt-get -y install unzip
unzip terraform_${VERSION}_${OS_NAME}_amd64.zip && rm -rf terraform_${VERSION}_${OS_NAME}_amd64.zip
sudo mv terraform /usr/local/bin/terraform
TERRAFORM="${VERSION}"
fi
fi
terraform version | xargs | awk '{print $2}'
# kops
echo "================================================================================"
_result "install kops..."
if [ "${OS_TYPE}" == "brew" ]; then
command -v kops > /dev/null || brew install kops
else
VERSION=$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | jq -r '.tag_name')
if [ "${KOPS}" != "${VERSION}" ] || [ "$(command -v kops)" == "" ]; then
_result " ${KOPS} >> ${VERSION}"
curl -LO https://github.com/kubernetes/kops/releases/download/${VERSION}/kops-${OS_NAME}-amd64
chmod +x kops-${OS_NAME}-amd64 && sudo mv kops-${OS_NAME}-amd64 /usr/local/bin/kops
KOPS="${VERSION}"
fi
fi
kops version 2>&1 | grep Version | xargs | awk '{print $2}'
# helm
echo "================================================================================"
_result "install helm..."
if [ "${OS_TYPE}" == "brew" ]; then
command -v helm > /dev/null || brew install kubernetes-helm
else
# VERSION=$(curl -s https://api.github.com/repos/helm/helm/releases/latest | jq -r '.tag_name')
VERSION="v2.13.1"
if [ "${HELM}" != "${VERSION}" ] || [ "$(command -v helm)" == "" ]; then
_result " ${HELM} >> ${VERSION}"
curl -L https://storage.googleapis.com/kubernetes-helm/helm-${VERSION}-${OS_NAME}-amd64.tar.gz | tar xz
sudo mv ${OS_NAME}-amd64/helm /usr/local/bin/helm && rm -rf ${OS_NAME}-amd64
HELM="${VERSION}"
fi
fi
helm version --client --short | xargs | awk '{print $2}' | cut -d'+' -f1
# draft
echo "================================================================================"
_result "install draft..."
if [ "${OS_TYPE}" == "brew" ]; then
if [ "$(command -v draft)" == "" ]; then
brew tap azure/draft && brew install azure/draft/draft
fi
else
VERSION=$(curl -s https://api.github.com/repos/Azure/draft/releases/latest | jq -r '.tag_name')
if [ "${DRAFT}" != "${VERSION}" ] || [ "$(command -v draft)" == "" ]; then
_result " ${DRAFT} >> ${VERSION}"
curl -L https://azuredraft.blob.core.windows.net/draft/draft-${VERSION}-${OS_NAME}-amd64.tar.gz | tar xz
sudo mv ${OS_NAME}-amd64/draft /usr/local/bin/draft && rm -rf ${OS_NAME}-amd64
DRAFT="${VERSION}"
fi
fi
draft version --short | xargs | cut -d'+' -f1
# aws-iam-authenticator
echo "================================================================================"
_result "install aws-iam-authenticator..."
if [ "${OS_TYPE}" == "brew" ]; then
command -v aws-iam-authenticator > /dev/null || brew install aws-iam-authenticator
else
# VERSION=$(curl -s https://api.github.com/repos/kubernetes-sigs/aws-iam-authenticator/releases/latest | jq -r '.tag_name' | cut -d'v' -f2)
VERSION="0.3.0"
if [ "${AWS_AUTH}" != "${VERSION}" ] || [ "$(command -v draft)" == "" ]; then
_result " ${AWS_AUTH} >> ${VERSION}"
URL="https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v${VERSION}/heptio-authenticator-aws_${VERSION}_${OS_NAME}_amd64"
curl -L -o aws-iam-authenticator ${URL}
chmod +x aws-iam-authenticator && sudo mv aws-iam-authenticator /usr/local/bin/aws-iam-authenticator
AWS_AUTH="${VERSION}"
fi
fi
echo "${VERSION}"
# guard
echo "================================================================================"
_result "install guard..."
VERSION=$(curl -s https://api.github.com/repos/appscode/guard/releases/latest | jq -r '.tag_name')
if [ "${GUARD}" != "${VERSION}" ]; then
_result " ${GUARD} >> ${VERSION}"
curl -LO https://github.com/appscode/guard/releases/download/${VERSION}/guard-${OS_NAME}-amd64
chmod +x guard-${OS_NAME}-amd64 && sudo mv guard-${OS_NAME}-amd64 /usr/local/bin/guard
GUARD="${VERSION}"
fi
guard version 2>&1 | grep 'Version ' | xargs | awk '{print $3}'
# clean
echo "================================================================================"
_result "clean all..."
if [ "${OS_TYPE}" == "apt" ]; then
sudo apt clean all
sudo apt autoremove -y
elif [ "${OS_TYPE}" == "yum" ]; then
sudo yum clean all
elif [ "${OS_TYPE}" == "brew" ]; then
brew cleanup
fi
echo "================================================================================"
cat << EOF > ${CONFIG}
# version
DATE="${DATE}"
KUBECTL="${KUBECTL}"
TERRAFORM="${TERRAFORM}"
KOPS="${KOPS}"
HELM="${HELM}"
DRAFT="${DRAFT}"
AWS_AUTH="${AWS_AUTH}"
GUARD="${GUARD}"
EOF