-
Notifications
You must be signed in to change notification settings - Fork 0
/
more-ri.sh
executable file
·184 lines (147 loc) · 3.81 KB
/
more-ri.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
#!/bin/sh
generateRandomSalt(){
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}
changeAccountToUser(){
su - "dev"
}
checkEnvVariable(){
if [ -z "$USERPASSWORD" ]; then
echo "please do export USERPASSWORD=<yourpasswordhere>"
exit 1
fi
}
installDocker(){
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt update
apt-cache policy docker-ce
apt install -y docker-ce
usermod -aG docker "dev"
systemctl start docker
systemctl enable docker
}
addSwap(){
message "ADDING 4GB OF SWAP"
fallocate -l 4G /swap
chmod 600 /swap
mkswap /swap
swapon /swap
cp /etc/fstab /etc/fstab.bak
echo '/swap none swap sw 0 0' | sudo tee -a /etc/fstab
free
finish
}
installBasicSoftware(){
message "UPDATING THE SYSTEM AND INSTALLING ESSENTIALS SOFTWARES FOR THE NODE"
apt update && apt upgrade -y
apt install -y \
build-essential \
software-properties-common \
git \
bash \
zip \
wget \
zsh \
vim \
ufw \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \
fail2ban \
openssl \
gnupg \
npm \
nodejs \
unattended-upgrades \
jq
npm install gtop -g
systemctl enable unattended-upgrades
systemctl start unattended-upgrades
curl https://raw.githubusercontent.com/Y0lan/ot-node-installer/main/config/50unattended-upgrades > /etc/apt/apt.conf.d/50unattended-upgrades
curl https://raw.githubusercontent.com/Y0lan/ot-node-installer/main/config/20auto-upgrades > /etc/apt/apt.conf.d/20auto-upgrades
curl -sSL https://repos.insights.digitalocean.com/install.sh | sudo bash
wget -qO- https://repos-droplet.digitalocean.com/install.sh | sudo bash
installDocker
finish
}
setupFail2Ban(){
message "SETTING UP FAIL2BAN SECURITY"
systemctl start fail2ban
systemctl enable fail2ban
curl https://raw.githubusercontent.com/Y0lan/ot-node-installer/main/config/jail.local > /etc/fail2ban/jail.local
systemctl restart fail2ban
finish
}
setupZSH(){
username="dev"
message "ADDING ZSH AS DEFAULT SHELL FOR $username"
chsh -s $(which zsh) "$username"
touch /home/$username/.zshrc
finish
}
message(){
echo
echo
echo "#############"
echo "$1"
echo "#############"
echo
echo
}
finish(){
echo
echo "DONE"
}
setupServer(){
installBasicSoftware
createUser
disableRootLogin
addSwap
setupZSH
setupFirewall
setupFail2Ban
unattended-upgrades --dry-run --debug
}
setupFirewall(){
message "ENABLE FIREWALL AND OPEN SSH AND NODE PORT"
ufw allow OpenSSH
ufw allow 8900
ufw allow 5278
ufw allow 3000
ufw allow 22/tcp
ufw show added
yes | ufw enable
ufw status
finish
}
addSudoTo(){
usermod -aG sudo "$1"
}
createUser(){
username="dev"
message "CREATING USER $username"
adduser --disabled-password --gecos "" "$username"
finish
message "ADDING USER $username TO SUDO"
addSudoTo "$username"
finish
message "ALLOWING SSH CONNECTION FOR $username"
cp -r ~/.ssh /home/"$username"
chown -R "$username:$username" /home/"$username"/.ssh
finish
message "ADDING SUDO PASSWORD $USERPASSWORD TO $username"
usermod -p $(openssl passwd -1 -salt $(generateRandomSalt) "$USERPASSWORD") "$username"
finish
}
disableRootLogin(){
message "DISABLING ROOT LOGIN"
sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
finish
}
checkEnvVariable
message "OT-NODE-INSTALLER V1.0"
echo "IT WILL TAKE SOME TIME, HANG OUT..."
setupServer
changeAccountToUser