-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmokeping.sh
114 lines (102 loc) · 4.46 KB
/
smokeping.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
#!/usr/bin/env bash
#
clear
echo "This script will automate the installation of Nginx and SmokePing"
echo "It will ask you for fully qualified name (example.server.com) as well"
echo "your email address. The email address is simply used to register the"
echo "SSL Certificate against and also to notify you if the certificate fails"
echo "to renew every 90 days in an automated fashion"
echo
echo "If you want to exit this script without continuing, please press CTRL-C"
echo
read -p "What is the FQDN of the web server: " wsname
read -p "What is your email address: " userem
# lets take the "wsname" var and make sure it actually works
resolvedIP=$(nslookup "$wsname" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
[[ -z "$resolvedIP" ]] && echo "$wsname" lookup failure && exit || echo "$wsname" resolved to "$resolvedIP"
# now lets check to make sure the email address entered is valud
regex="^(([A-Za-z0-9]+((\.|\-|\_|\+)?[A-Za-z0-9]?)*[A-Za-z0-9]+)|[A-Za-z0-9]+)@(([A-Za-z0-9]+)+((\.|\-|\_)?([A-Za-z0-9]+)+)*)+\.([A-Za-z]{2,})+$"
if [[ $userem =~ ${regex} ]]; then
echo "Valid emain...continuing"
else
echo "$userem is not a valid email"
exit
fi
# TODO: Grab some user information as well as possibly
# grabbing the hostname or even using wsname
# and populating the default Targets
# and changing the config with sed
#
#read -p "What is your First and Last Name: " flname
#
#
#
apt update -y
apt dist-upgrade -y
apt install nginx -y
apt install fcgiwrap -y
apt install smokeping -y
cp /usr/share/doc/fcgiwrap/examples/nginx.conf /etc/nginx/fcgiwrap.conf
tee -a /etc/nginx/sites-available/smokeping <<EOF
server {
listen 80;
listen [::]:80;
server_name $wsname;
location = /smokeping/smokeping.cgi {
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/smokeping.cgi;
fastcgi_param QUERY_STRING \$query_string;
fastcgi_param REQUEST_METHOD \$request_method;
fastcgi_param CONTENT_TYPE \$content_type;
fastcgi_param CONTENT_LENGTH \$content_length;
fastcgi_param REQUEST_URI \$request_uri;
fastcgi_param DOCUMENT_URI \$document_uri;
fastcgi_param DOCUMENT_ROOT \$document_root;
fastcgi_param SERVER_PROTOCOL \$server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR \$remote_addr;
fastcgi_param REMOTE_PORT \$remote_port;
fastcgi_param SERVER_ADDR \$server_addr;
fastcgi_param SERVER_PORT \$server_port;
fastcgi_param SERVER_NAME \$server_name;
fastcgi_param HTTPS \$https if_not_empty;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
}
location ^~ /smokeping/ {
alias /usr/share/smokeping/www/;
index smokeping.cgi;
gzip off;
}
location / {
return 301 http://\$server_name/smokeping/smokeping.cgi;
}
}
EOF
ln -s /etc/nginx/sites-available/smokeping /etc/nginx/sites-enabled/smokeping
rm /etc/nginx/sites-enabled/default
tee -a /etc/nginx/sites-available/no-site <<EOF
# If a client requests for an unknown server name and there's no default server
# name defined, Nginx will serve the first server configuration found. To
# prevent this, we have to define a default server name and drop the request.
server {
listen 80 default_server deferred;
listen [::]:80 default_server deferred;
server_name _;
# Return 444 (No Response)
return 444;
}
EOF
ln -s /etc/nginx/sites-available/no-site /etc/nginx/sites-enabled/no-site
service nginx restart
#sudo apt install -y certbot python3-certbot-nginx
sudo snap install core; sudo snap refresh core
sudo apt-get remove certbot -y
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx --redirect -d $wsname -m $userem --agree-tos -n
apt autoremove -y
clear
echo "If everything went correct you should be able to visit https://$wsname"
echo "There is a redirect in place that will take you to the default SmokePing"
echo "page and show you the graphs"