-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsslsetup
More file actions
executable file
·162 lines (120 loc) · 4.64 KB
/
Copy pathsslsetup
File metadata and controls
executable file
·162 lines (120 loc) · 4.64 KB
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
#!/bin/bash
echo "#####################################################"
echo "# Setting up SSL #"
echo "#####################################################"
echo "Enter your name and press [ENTER]: "
read -p "Name: " USER
echo ""
echo "Hello $USER. This Script will Help You Set Up SSL Encryption on your Digital Ocean Droplet. I need to ask you a few questions first before we get started."
echo ""
echo "Enter your E-Mail address and press [ENTER]: "
read -p "E-Mail: " USER_EMAIL
echo ""
echo "We will now enter the first DOMAIN NAME that you want to encrypt."
MOREDOMAINS="N"
DOMAINS_TO_ENCRYPT=()
COUNTER=0
function regdomain {
echo ""
echo "Please use the base name (ex: example.com, crm.example.com) and do not include http:// or www..."
echo "Enter your Domain or SubDomain Name and press [ENTER]: "
read -p "Domain: " DOMAIN_NAME[$COUNTER]
#Just making sure that they didn't put www before the domain name.
DOMAIN_NAME[$COUNTER]=$(sed 's/www.//g' <<<"${DOMAIN_NAME[$COUNTER]}")
echo ""
echo "Let me check to make sure that ${DOMAIN_NAME[$COUNTER]} is valid and is working correctly."
if ping -c 1 ${DOMAIN_NAME[$COUNTER]} &> /dev/null
then
DOMAINS_TO_ENCRYPT+=("-d ${DOMAIN_NAME[$COUNTER]}")
echo ""
echo "Great! I was able to Connect Successfuly to ${DOMAIN_NAME[$COUNTER]}!"
if ping -c 1 "www.${DOMAIN_NAME[$COUNTER]}" &> /dev/null
then
DOMAIN_NAME_WWW[$COUNTER]="www.${DOMAIN_NAME[$COUNTER]}"
DOMAINS_TO_ENCRYPT+=("-d www.${DOMAIN_NAME[$COUNTER]}")
echo "Adding [www] too..."
fi
if [ -n "$INSTALL_LOC" ]
then
INSTALL_LOC[$COUNTER]="$INSTALL_LOC"
else
INSTALL_LOC[$COUNTER]="/var/www/html"
fi
echo ""
echo "I need to know where ${DOMAIN_NAME[$COUNTER]} is installed on your server [The file path]."
echo "The Default location is [${INSTALL_LOC[$COUNTER]}]. Is this where ${DOMAIN_NAME[$COUNTER]} is installed?"
echo ""
if ask "Please enter [Y] or [N] and press [ENTER]: " Y; then
# All is good
echo "Great! The Domain is Installed at ${INSTALL_LOC[$COUNTER]}"
else
echo ""
echo "Please enter the exact install location (ex. /var/www/owncloud, /var/www/churchcrm, /var/www/html) and press [ENTER]: "
read INSTALL_LOC[$COUNTER]
fi
else
echo ""
echo "WARNING: COULD NOT CONNECT TO ${DOMAIN_NAME[$COUNTER]}. Please check your networking settings in DigitalOcean and then run this installer again. Thank you."
exit 1
fi
echo ""
echo "Do you have any other domains or subdomains that you would like to encrypt at this time?"
echo "Please enter [Y] or [N] and press [ENTER]: "
let COUNTER=COUNTER+1
echo ""
if ask "Do you want to Encrypt any other Domains or SubDomains?: "; then
regdomain
fi
}
ask() {
# http://djm.me/ask
local prompt default REPLY
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read REPLY </dev/tty
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
regdomain
echo ""
echo "Great! We're done that part. Now I need to do a few things with the Apache Configuration file, and then we will be ready to contact LetsEncrypt."
echo ""
COUNTER=0;
for i in ${DOMAIN_NAME[@]}; do
echo "Working on the Apache Config File for $i..."
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/$i.conf
sed -i "s/webmaster@localhost/$USER_EMAIL/g" /etc/apache2/sites-available/$i.conf
sed -i "s#/var/www/html#${INSTALL_LOC[$COUNTER]}#g" /etc/apache2/sites-available/$i.conf
sed -i "/ServerAdmin/a ServerName $i" /etc/apache2/sites-available/$i.conf
sed -i "/ServerName/a ServerAlias www.$i" /etc/apache2/sites-available/$i.conf
a2ensite $i
let COUNTER=COUNTER+1
done
#Reloading Apache before calling LetsEncrypt
echo "Reloading Apache"
service apache2 reload
echo "Connecting to LetsEncrypt..."
letsencrypt --apache ${DOMAINS_TO_ENCRYPT[@]}
echo "30 2 * * 1 /usr/bin/letsencrypt renew >> /var/log/le-renew.log" >> /var/spool/cron/crontabs/root
chmod 600 /var/spool/cron/crontabs/root
service apache2 reload