-
Notifications
You must be signed in to change notification settings - Fork 4
/
installterraform.sh
196 lines (149 loc) · 6.19 KB
/
installterraform.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
#!/bin/bash
# -*- Mode: sh; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Authors:
# Kevin Fowlks <fowlk1kd@gmail.com>
#
# Description:
# A post base tool installation bash script for Ubuntu 16.04+
#
# Legal Preamble:
#
# This script is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This script is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <https://www.gnu.org/licenses/gpl-3.0.txt>
# tab width
tabs 4
clear
ROOT_UID=0
E_NOTROOT=1
ADMIN_EMAIL=fowlk1kd@gmail.com
DEBIAN_FRONTEND=noninteractive
echoRed() {
echo -e "\E[1;31m$1"
echo -e '\e[0m'
}
echoGreen() {
echo -e "\E[1;32m$1"
echo -e '\e[0m'
}
echoCyan() {
echo -e "\E[1;36m$1"
echo -e '\e[0m'
}
echoMagenta() {
echo -e "\E[1;35m$1"
echo -e '\e[0m'
}
check_errs()
{
# Function. Parameter 1 is the return code
# Para. 2 is text to display on failure.
if [ "${1}" -ne "0" ]; then
echoRed "ERROR # ${1} : ${2}"
# as a bonus, make our script exit with the right error code.
if [ "$#" -eq 3 ]; then
echoCyan "cleaning file from failed script attempt "
rm -f ${3}
check_errs $? "Failed to remove file - ${3}"
fi
exit ${1}
fi
}
if [ $UID -ne $ROOT_UID ]
then
echoRed "﴾͡๏̯͡๏﴿ O'RLY? Sorry You must be root to run this script... Quiting";
exit $E_NOTROOT
else
echoGreen "(ง ͠° ͟ل͜ ͡°)ง go go get em cowboy"
fi
#sudo apt-add-repository --yes --force-yes ppa:ansible/ansible
#sudo apt-get --yes --force-yes update
#sudo apt-get --yes --force-yes install ansible
export $DEBIAN_FRONTEND
apt-get --yes --force-yes update
check_errs $? "Failed to apt-get update"
apt-get --yes --force-yes upgrade
check_errs $? "Failed to apt-get upgrade"
apt-get --yes --force-yes install debconf-doc
check_errs $? "Failed to apt-get debconf-doc"
apt-get --yes --force-yes install unattended-upgrades
check_errs $? "Failed to configure unattended-upgrades"
truncate -s 0 /etc/apt/apt.conf.d/10periodic
check_errs $? "Failed to truncate 10periodic"
echo 'APT::Periodic::Update-Package-Lists "1";' > /etc/apt/apt.conf.d/10periodic
echo 'APT::Periodic::Download-Upgradeable-Packages "1";' >> /etc/apt/apt.conf.d/10periodic
echo 'APT::Periodic::AutocleanInterval "7";' >> /etc/apt/apt.conf.d/10periodic
echo 'APT::Periodic::Unattended-Upgrade "1";' >> /etc/apt/apt.conf.d/10periodic
echo '// Automatically upgrade packages from these (origin, archive) pairs' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo 'Unattended-Upgrade::Allowed-Origins { ' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo ' // ${distro_id} and ${distro_codename} will be automatically expanded' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo ' "${distro_id} stable";' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo ' "${distro_id} ${distro_codename}-security";' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo ' "${distro_id} ${distro_codename}-updates";' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo '// "${distro_id} ${distro_codename}-proposed-updates";' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo '};' >> /etc/apt/apt.conf.d/50unattended-upgrades
apt-get --yes --force-yes install fail2ban
check_errs $? "Failed to install fail2ban"
#ufw allow from {your-ip} to any port 22
#check_errs $? "Failed to configure ufw #1"
ufw allow 22
check_errs $? "Failed to configure ufw #1"
ufw allow 80
check_errs $? "Failed to configure ufw #2"
ufw allow 443
check_errs $? "Failed to configure ufw #3"
ufw allow 9252
check_errs $? "Failed to configure ufw #4"
ufw enable
check_errs $? "Failed to configure ufw #5"
# Secure Node
sed -i '/^PermitRootLogin/s/yes/prohibit-password/' /etc/ssh/sshd_config
check_errs $? "Failed to config sshd config #1"
sed -i "s/.*RSAAuthentication.*/RSAAuthentication yes/g" /etc/ssh/sshd_config
check_errs $? "Failed to config sshd config #2"
sed -i "s/.*PubkeyAuthentication.*/PubkeyAuthentication yes/g" /etc/ssh/sshd_config
check_errs $? "Failed to config sshd config #3"
sed -i "s/.*PasswordAuthentication.*/PasswordAuthentication no/g" /etc/ssh/sshd_config
check_errs $? "Failed to config sshd config #4"
sed -i "s/.*AuthorizedKeysFile.*/AuthorizedKeysFile\t\.ssh\/authorized_keys/g" /etc/ssh/sshd_config
check_errs $? "Failed to config sshd config #5"
sed -i "s/.*PermitRootLogin.*/PermitRootLogin no/g" /etc/ssh/sshd_config
check_errs $? "Failed to config sshd config #6"
sshd -t
check_errs $? "Failed sshd config is not valid"
service sshd restart
check_errs $? "Failed to restart sshd"
# Install Log Watch
apt-get --yes --force-yes install logwatch
check_errs $? "Failed to install logwatch"
echo >> '/usr/sbin/logwatch --output mail --mailto $ADMIN_EMAIL --detail high' >> /etc/cron.daily/00logwatch
check_errs $? "Failed to configure logwatch"
# Install Docker
#curl -sSL https://get.docker.com/ | sh
#check_errs $? "Failed to install docker"
#docker run -d --name gitlab-runner --restart always \
# -v /var/run/docker.sock:/var/run/docker.sock \
# -v /srv/gitlab-runner/config:/etc/gitlab-runner \
# gitlab/gitlab-runner:alpine
#check_errs $? "Failed to configure docker"
#sudo usermod -aG docker deployer
#check_errs $? "Failed to add user deployer to group docker"
#mkdir -p /srv/gitlab-runner/config
#check_errs $? "Failed to create /srv/gitlab-runner/config directory"
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
check_errs $? "Failed to add apt-key hashicorp"
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
check_errs $? "Failed to add repository hashicorp"
sudo apt-get --yes --force-yes update
check_errs $? "Failed to add force update hashicorp"
sudo --yes --force-yes apt-get install terraform
check_errs $? "Failed to add force update hashicorp"