-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathssl-install.sh
100 lines (94 loc) · 2.7 KB
/
ssl-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
#!/bin/sh
# ssl installation script
set -e
WEB_CONF=/etc/apache2/conf-enabled
UBUNTU_VER=$(lsb_release -rs)
APACHE_VER=$(apache2 -v | awk -F"[..]" 'NR<2{print $2}')
WEB=/opt
HIE=$WEB/hieofone-as
NOSHCRON=/etc/cron.d/nosh-cs
# Check if running as root user
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Aborting." 1>&2
exit 1
fi
read -e -p "Enter your domain name (example.com): " -i "" DOMAIN
if [[ ! -z $DOMAIN ]]; then
if [ ! -f /usr/local/bin/certbot-auto ]; then
cd /usr/local/bin
wget https://dl.eff.org/certbot-auto
chmod a+x /usr/local/bin/certbot-auto
./certbot-auto --apache certonly -d $DOMAIN
fi
if [ -e "$WEB_CONF"/hie.conf ]; then
rm "$WEB_CONF"/hie.conf
fi
touch "$WEB_CONF"/hie.conf
APACHE_CONF="<VirtualHost _default_:80>
DocumentRoot $HIE/public/
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
DocumentRoot $HIE/public/
SSLEngine on
SSLProtocol all -SSLv2 -SSLv3
ServerName $DOMAIN
SSLCertificateFile /etc/letsencrypt/live/$DOMAIN/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
<FilesMatch \"\.(cgi|shtml|phtml|php)$\">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch \"MSIE [2-6]\" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
BrowserMatch \"MSIE [17-9]\" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
<Directory $HIE/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride None"
if [ "$APACHE_VER" = "4" ]; then
APACHE_CONF="$APACHE_CONF
Require all granted"
else
APACHE_CONF="$APACHE_CONF
Order allow,deny
allow from all"
fi
APACHE_CONF="$APACHE_CONF
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /\$1 [L,R=301]
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
<IfModule mod_php5.c>
php_value upload_max_filesize 512M
php_value post_max_size 512M
php_flag magic_quotes_gpc off
php_flag register_long_arrays off
</IfModule>
</Directory>"
echo "$APACHE_CONF" >> "$WEB_CONF"/hie.conf
echo "SSL Certificate set for $DOMAIN"
/etc/init.d/apache2 restart
echo "Restarting Apache service."
if [ -f $NOSHCRON ]; then
rm -rf $NOSHCRON
fi
touch $NOSHCRON
echo "30 0 * * 1 root /usr/local/bin/certbot-auto renew >> /var/log/le-renew.log" >> $NOSHCRON
chown root.root $NOSHCRON
chmod 644 $NOSHCRON
echo "Created Let'sEncrypt cron scripts."
fi
exit 0