-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathbootstrap_server_ubuntu.sh
executable file
·93 lines (75 loc) · 2.17 KB
/
bootstrap_server_ubuntu.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
#!/bin/bash
TOPDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
HOSTNAME=${1:-creativecommons.org}
DBNAME=${2:-wordpress}
DBUSER=${3:-dbuser}
DBPASS=${4:-}
#
# Install base system dependencies
#
apt-get update
if apt-get -y install `cat ${TOPDIR}/config/required_packages.txt`
then
echo "Required packages installed, proceeding with setup."
else
echo "Could not install required packages, aborting setup."
exit 1
fi
#
# Configure Apache:
#
# 1. Copy config files into place
if grep -q "apache.conf" /etc/apache2/httpd.conf
then
echo "Note: /etc/apache2/httpd.conf seems to be loading an apache.conf file,"
echo "leaving it alone. If that's not the CC apache.conf file, then you'll"
echo "need to add the Include line manually."
else
echo "Include ${TOPDIR}/config/apache.conf" >> /etc/apache2/httpd.conf
fi
cat <<EOF > /etc/apache2/sites-available/${HOSTNAME}
<VirtualHost *:80>
Use CCVHost ${HOSTNAME} http ${TOPDIR} /var/log/apache2/${HOSTNAME}
</VirtualHost>
EOF
if [ -f /etc/ssl/private/${HOSTNAME}.key ]
then
cat <<EOF >> /etc/apache2/sites-available/${HOSTNAME}
<VirtualHost *:443>
Use CCVHost ${HOSTNAME} https ${TOPDIR} /var/log/apache2/${HOSTNAME}
SSLEngine on
SSLCertificateFile /etc/ssl/private/${HOSTNAME}.crt
SSLCertificateKeyFile /etc/ssl/private/${HOSTNAME}.key
SSLCACertificateFile /etc/ssl/certs/RapidSSL_CA_bundle.pem
</VirtualHost>
EOF
fi
# 2. Create logging directory
mkdir -p /var/log/apache2/${HOSTNAME}
chown root.adm /var/log/apache2/${HOSTNAME}
chmod 750 /var/log/apache2/${HOSTNAME}
# 3. Enable mods and site
for i in macro php5 rewrite ssl fcgid
do
a2enmod $i
done
a2ensite ${HOSTNAME}
# 4. Restart Apache
service apache2 restart
#
# Create a MySQL DB for WordPress
#
# run mysql to see if the root user has a password set
if mysql -u root -e ""
then
mysql -u root mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${DBNAME};
GRANT ALL ON ${DBNAME} TO '${DBUSER}'@'localhost' IDENTIFIED BY '${DBPASS}';
EOF
else
echo "Enter the MySQL root password:"
mysql -u root -p mysql <<EOF
CREATE DATABASE IF NOT EXISTS ${DBNAME};
GRANT ALL ON ${DBNAME} TO '${DBUSER}'@'localhost' IDENTIFIED BY '${DBPASS}';
EOF
fi