-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-install.sh
283 lines (226 loc) · 6.29 KB
/
server-install.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
#!/bin/bash
#Name : server-install
#Basic installation script for most widespread web services and utility packets.
#Version : 0.2
#Author : Mathieu Morgat
#Github page : https://github.com/V4nkor/server-install
prodDirectory="/opt/server-install"
testingDirectory="$(pwd 2>&1)"
#--------- Global functions ------------#
showHelp() {
echo "Choose packages and services you wish to install using the dialog windows."
echo "Use the arrow keys to navigate"
echo "use space to select / unselect"
echo "press enter to confirm"
exit 1
}
uninstallScript(){
cmd=(dialog --title "Uninstall" \ --backtitle "Uninstall" \ --yesno "Are you sure you want to uninstall ?" 7 60)
yesno=$("${cmd[@]}" 2>&1 >/dev/tty)
case $yesno in
0)
sudo $testingDirectory/server-uninstall-all.sh
exit 0 ;;
1)
exit 1 ;;
255)
exit 1 ;;
esac
exit 1
}
if [ "$EUID" -ne 0 ]
then echo "This script must be run as root or with sudo"
exit 1
fi
case "${1}" in
"-h" | "help" | "-H")
showHelp ;;
"-u")
uninstallScript
esac
#--------- Initialise packets dialog ------------#
cmd=(dialog --keep-tite --separate-output --checklist "Important packets and utilities :" 22 76 16)
options=(
nano "nano" on
vim "vim" off
wget "wget" on
curl "curl" on
unzip "unzip" on
git "git" on
ufw "ufw" off
)
#--------- Store packets choices in variable ---------#
packets=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
#--------- Initialise services dialog ------------#
cmd=(dialog --keep-tite --separate-output --checklist "Web services to install :" 22 76 16)
options=(
ssh "ssh" on
apache2 "apache2" on
php "php" on
mysql "MySQL" on
composer "Composer" on
)
#--------- Store services choices in variable ---------#
services=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
#--------- Packet Functions ------------#
#Install nano
installNano(){
if (($? == 0)); then eval "apt-get install nano"; fi
}
#Install vim
installVim(){
printf '\e[1;31m%-6s\e[m\n' "!!Not yet implemented -> WIP!!"
}
#Install wget
installWget(){
printf '\e[1;31m%-6s\e[m\n' "!!Not yet implemented -> WIP!!"
}
#Install curl
installCurl(){
printf '\e[1;31m%-6s\e[m\n' "!!Not yet implemented -> WIP!!"
}
#Install unzip
installUnzip(){
printf '\e[1;31m%-6s\e[m\n' "!!Not yet implemented -> WIP!!"
}
#Install git
installGit(){
printf '\e[1;31m%-6s\e[m\n' "!!Not yet implemented -> WIP!!"
}
#Install ufw
installUfw(){
printf '\e[1;31m%-6s\e[m\n' "!!Not yet implemented -> WIP!!"
}
if ([ -z "$packets" ] && [ -z "$services" ]); then printf '\e[1;31m%-6s\e[m\n' "!!Nothing selected -> Exiting!!" && exit 1 ; fi
# Update existing packets
sudo apt-get update -y
#--------- Processing selected packets ---------#
for packet in $packets
do
case $packet in
nano)
printf '\e[1;34m%-6s\e[m\n' "----- Installing nano -----"
installNano ;;
vim)
printf '\e[1;34m%-6s\e[m\n' "----- Installing vim -----"
installVim ;;
wget)
printf '\e[1;34m%-6s\e[m\n' "----- Installing wget -----"
installWget ;;
curl)
printf '\e[1;34m%-6s\e[m\n' "----- Installing curl -----"
installCurl ;;
unzip)
printf '\e[1;34m%-6s\e[m\n' "----- Installing unzip -----"
installUnzip ;;
git)
printf '\e[1;34m%-6s\e[m\n' "----- Installing git -----"
installGit ;;
ufw)
printf '\e[1;34m%-6s\e[m\n' "----- Installing ufw -----"
installUfw ;;
esac
done
#--------- Services Functions ---------#
#Install SSH functions and start service
installSSH(){
if (($? == 0)); then eval "apt-get install ssh -y"; fi
if (($? == 0)); then eval "service ssh start"; fi
OUTPUT="$(systemctl status ssh 2>&1)"
printf "$OUTPUT \n"
}
#Install Apache functions and start service
installApache(){
if (($? == 0)); then eval "apt-get -y install apache2"; fi
if (($? == 0)); then eval "a2enmod ssl"; fi
if (($? == 0)); then eval "a2enmod rewrite"; fi
if (($? == 0)); then eval "/etc/init.d/apache2 restart"; fi
OUTPUT="$(systemctl status apache2 2>&1)"
printf "$OUTPUT \n"
}
#Install PHP functions and start service
installPHP(){
if (($? == 0)); then eval "apt-get -y install php-common libapache2-mod-php php-cli"; fi
if (($? == 0)); then eval "/etc/init.d/apache2 restart"; fi
OUTPUT="$(php --version 2>&1)"
printf "$OUTPUT \n"
}
#Install MySQL and setup with base options
installMySQL(){
#Initialise MySQL dialog
cmd=(dialog --separate-output --checklist "MySQL configuration :" 22 76 16)
options=(
mysql
)
#Store MySQL choices in variable
MySQL=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
}
#Install Composer
installComposer(){
printf "Not yet implemented -> WIP\n"
}
#--------- Processing selected services ---------#
for service in $services
do
case $service in
ssh)
printf '\e[1;34m%-6s\e[m\n' "----- Installing SSH -----"
installSSH ;;
apache)
printf '\e[1;34m%-6s\e[m\n' "----- Installing Apache2 -----"
installApache ;;
php)
printf '\e[1;34m%-6s\e[m\n' "----- Installing PHP -----"
installPHP ;;
mysql)
printf '\e[1;34m%-6s\e[m\n' "----- Installing MySQL -----"
printf '\e[1;31m%-6s\e[m\n' "!!Work in progress!!"
#installMySQL
;;
composer)
printf '\e[1;34m%-6s\e[m\n' "----- Installing Composer -----"
installComposer ;;
esac
done
#Exit script when finished
exit 0
#--------- Documentation ------------#
: <<'END_OF_DOCS'
=head1 NAME
Basic installation script for most widespread web services and utility packets.
=head1 SYNOPSIS
server-install [-h] [-u] [OPTIONS]
=head1 OPTIONS
-h Call help function
-H Call help function
help Call help function
-u Uninstall program
=head1 DESCRIPTION
This script was created in order to simplify the process of seting up a web server with the help of dialog windows
users can select which packets they wish to install and simplifies the setup of web services.
Available packets :
-nano
-vim
-wget
-curl
-unzip
-git -> user and SSH key config planned
-ufw -> basic web firewall config planned
Currently supported services :
-ssh
-apache2
-php
Work in progress :
-MySQL
-Composer
[...]
=head1 LICENSE AND COPYRIGHT
This script is under a GNU V 3.0 licence.
You are free to :
-Use this script
-Modify it to satisfy your use case
-Redistribute this script
-Share any modification made
Mathieu Morgat - 2023
=cut
END_OF_DOCS