-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.sh
205 lines (164 loc) · 6.59 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
#!/bin/bash
##
## setup.sh - Canivete DevOps
##
## Site : https://alexjunio.com.br
## Autor : Alex Junio <contato@alexjunio.com.br>
##
## ------------------------------------------------------------------------ ##
## Esse script automatiza o setup de diversas ferramentas
## como: Docker, Ansible, Terraform e outros.
## ------------------------------------------------------------------------ ##
## ------------------------------------------------------------------------ ##
## CORES P/ TERMINAL
## ------------------------------------------------------------------------ ##
red=`echo -en "\e[31m"`
normal=`echo -en "\e[0m"`
green=`echo -en "\e[32m"`
orange=`echo -en "\e[33m"`
blue=`echo -en "\e[34m"`
bold=`echo -en "\e[1m"`
## ------------------------------------------------------------------------ ##
## VERIFICAO DO SO E EXECUCAO DA FUNCAO CORRESPONDENTE
## ------------------------------------------------------------------------ ##
# Detect OS
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
else
OS=$(uname -s)
fi
## ------------------------------------------------------------------------ ##
## INSTALACAO DO TERRAFORM
## ------------------------------------------------------------------------ ##
# Instalacao do terraform
setupterraform () {
# Verifica se o terraform está instalado
if ! command -v terraform &> /dev/null
then
clear
echo "Terraform não está instalado, instalando terraform..."
sleep 3
# Instalação do terraform
# Perform actions based on OS
if [[ "$OS" == "Debian GNU/Linux" ]] || [[ "$OS" == "Ubuntu" ]]; then
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform -y
elif [[ "$OS" == "CentOS Linux" ]] && [[ "$(cat /etc/centos-release | awk '{print $4}' | awk -F '.' '{print $1}')" == "7" ]]; then
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
elif [[ "$OS" == "CentOS Linux" ]] && [[ "$(cat /etc/centos-release | awk '{print $4}' | awk -F '.' '{print $1}')" == "8" ]]; then
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
else
# Incompatible system
echo "Sistema Incompatível!"
fi
fi
}
## ------------------------------------------------------------------------ ##
## INSTALACAO DO DOCKER
## ------------------------------------------------------------------------ ##
# Instalacao do Docker e Docker compose
setupdocker () {
# Verifica se o Docker está instalado
if ! command -v docker &> /dev/null
then
clear
echo "Docker não está instalado, instalando Docker..."
sleep 3
# Instalação do Docker
curl -fsSL https://get.docker.com | bash
fi
}
## ------------------------------------------------------------------------ ##
## INSTALACAO DO ANSIBLE
## ------------------------------------------------------------------------ ##
# Instalacao do Ansible
setupansible () {
# Verifica se o Ansible está instalado
if ! command --version ansible &> /dev/null
then
clear
echo "Ansible não está instalado, instalando..."
sleep 3
# Instalação do terraform
# Perform actions based on OS
if [[ "$OS" == "Debian GNU/Linux" ]] || [[ "$OS" == "Ubuntu" ]]; then
# Atualiza o cache do apt
sudo apt update
# Instala as dependências necessárias
sudo apt install -y software-properties-common
sudo apt install -y python3 git unzip htop
# Adiciona o repositório do Ansible
sudo apt-add-repository --yes --update ppa:ansible/ansible
# Instala o Ansible
sudo apt install -y ansible
# Configura Host Ansible Local
rm -r /etc/ansible/hosts && bash src/ansible_hosts.sh
elif [[ "$OS" == "CentOS Linux" ]] && [[ "$(cat /etc/centos-release | awk '{print $4}' | awk -F '.' '{print $1}')" == "7" ]]; then
# Instala as dependências necessárias
yum install -y epel-release
# Instala o Ansible
sudo yum install -y ansible
# Configura Host Ansible Local
rm -r /etc/ansible/hosts && bash src/ansible_hosts.sh
elif [[ "$OS" == "CentOS Linux" ]] && [[ "$(cat /etc/centos-release | awk '{print $4}' | awk -F '.' '{print $1}')" == "8" ]]; then
# Instala as dependências necessárias
yum install -y epel-release
# Instala o Ansible
yum install -y @ansible
# Configura Host Ansible Local
rm -r /etc/ansible/hosts && bash src/ansible_hosts.sh
else
# Incompatible system
echo "Sistema Incompatível!"
fi
fi
}
## ------------------------------------------------------------------------ ##
## INSTALACAO DO PACKER
## ------------------------------------------------------------------------ ##
# Instalacao do Packer
setuppacker () {
# Verifica se o Packer está instalado
if ! command --version Packer &> /dev/null
then
clear
echo "Packer não está instalado, instalando..."
sleep 3
# Instalação do Packer
# Perform actions based on OS
if [[ "$OS" == "Debian GNU/Linux" ]] || [[ "$OS" == "Ubuntu" ]]; then
# Verifica se a chave GPG já está instalada
if [[ $(sudo apt-key list | grep "HashiCorp" | wc -l) -gt 0 ]]; then
echo "A chave GPG já está instalada"
else
echo "Instalando a chave GPG"
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
fi
# Instalacao
sudo apt-get update && sudo apt-get -y install packer
elif [[ "$OS" == "CentOS Linux" ]] && [[ "$(cat /etc/centos-release | awk '{print $4}' | awk -F '.' '{print $1}')" == "7" ]]; then
# Instala as dependências necessárias
yum install -y yum-utils
# Add Repositorio
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
# Instalacao
sudo yum -y install packer
elif [[ "$OS" == "CentOS Linux" ]] && [[ "$(cat /etc/centos-release | awk '{print $4}' | awk -F '.' '{print $1}')" == "8" ]]; then
# Instala as dependências necessárias
yum install -y yum-utils
# Add Repositorio
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
# Instalacao
sudo yum -y install packer
else
# Incompatible system
echo "Sistema Incompatível!"
fi
fi
}