-
Notifications
You must be signed in to change notification settings - Fork 0
/
website-wordpress.sh
executable file
·147 lines (110 loc) · 3.87 KB
/
website-wordpress.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
#/bin/bash
# cd to dir script is run from
cd "$( dirname "${BASH_SOURCE[0]}" )"
if [ `id -u` -ne 0 ]; then
echo "Must be root to run this script"
exit 1
fi
if [ -z $3 ] ; then
echo -e "\nYou have not specified a wp-content directory, .htaccess file and mysqldump file to restore. Please specify "
echo "./webserver-setup.sh /path/to/wp-content /path/to/.htaccess /path/to/sqldump"
exit
else
wpcontentpath=$1
htaccesspath=$2
sqlrestorepath=$3
fi
# Check if wp-content is in the wpcontentpath
if ! echo $wpcontentpath | grep -q wp-content
then
echo "WARNING: The string 'wp-content' was not detected in the wp-content path"
echo "Your wp-content path is $wpcontentpath are you sure this is right?"
echo "continue? (y/n)"
read continueAnyway
if [ "$continueAnyway" != "y" ]; then
exit 1
fi
fi
# Check if .htaccess is in the htaccesspath
if ! echo $htaccesspath | grep -q htaccess
then
echo "WARNING: The string 'htaccess' was not detected in the htaccess path"
echo "Your htaccess path is $htaccesspath are you sure this is right?"
echo "continue? (y/n)"
read continueAnyway
if [ "$continueAnyway" != "y" ]; then
exit 1
fi
fi
#Config dir exists
if [ ! -d "configs" ]; then
echo "Main configs dir missing. Can't do anything without it. This contains all the templates to deploy to the system"
echo "If you have assumed you don't need this, you're wrong. Please put it back"
exit 1
fi
#Temp dir exists
if [ ! -d "temp" ]; then
mkdir temp
fi
chmod 700 temp
#temp webserver dir exists
if [ -d "temp/webserver" ]; then
echo "Cleaning up old config files"
rm -r "temp/webserver"
fi
./webserver.sh
# cp config to temp
cp -r configs/webserver temp/webserver
mysqlrootpassword=`cat /etc/mysqlrootpassword`
# Setup Mysql passwords
mysqlwordpresspassword=`pwgen -s 30 1 | tee /etc/mysqlwordpresspassword`
chmod 700 /etc/mysqlwordpresspassword
sed -i "s/%mysql-wordpress-password%/$mysqlwordpresspassword/g" temp/webserver/wordpress/wp-config.php
sed -i "s/%mysql-wordpress-password%/$mysqlwordpresspassword/g" temp/webserver/mysql-recreate-wordpress-db-user.sql
mysql --force -u root -p$mysqlrootpassword < temp/webserver/mysql-recreate-wordpress-db-user.sql
# Setup Users
mkdir /var/www/wordpress
useradd wordpress -d /var/www/wordpress -s /bin/false
# Setup apache virtualhost files
cp temp/webserver/apache/wordpress /etc/apache2/sites-available/wordpress
a2ensite wordpress
a2enmod ssl
a2enmod rewrite
a2enmod headers
a2enmod expires
# Install latest wordpress
wget -4 -O temp/webserver/latest.tar.gz http://wordpress.org/latest.tar.gz
tar -zxf temp/webserver/latest.tar.gz -C temp/webserver/.
cp -r temp/webserver/wordpress/* /var/www/wordpress/.
cp temp/webserver/wordpress/wp-config.php /var/www/wordpress/wp-config.php
echo -e "<?php\n `wget -4 https://api.wordpress.org/secret-key/1.1/salt/ -O - -q`\n?>" > temp/webserver/wordpress/wp-keys.php
if ! grep -q "SECURE_AUTH_SALT" temp/webserver/wordpress/wp-keys.php; then
echo "Error, donloading of wordpress secret-key salts failed"
echo "Continue? y/n"
read continue
if [ "$continue" != "y" ]; then
exit
fi
fi
#Copy over secret key salts to wordpress dir
cp temp/webserver/wordpress/wp-keys.php /var/www/wordpress/wp-keys.php
#Restore mysql restore database
mysql -u wordpress -p$mysqlwordpresspassword wordpress < $sqlrestorepath
if [ -d "$wpcontentpath" ]; then
echo "Now restoring wp-content - removing default wp-content and copying backup in"
rm -rf /var/www/wordpress/wp-content
cp -r $wpcontentpath /var/www/wordpress/.
echo ...done
else
echo "ERROR wp-content path: $wpcontentpath doesn't exist/not a directory!"
fi
if [ -f "$htaccesspath" ]; then
echo "Now restoring .htaccess"
cp $htaccesspath /var/www/wordpress/.htaccess
echo ...done
else
echo "ERROR .htaccess path: $htaccesspath doesn't exist/not a file!"
fi
chown -R wordpress:wordpress /var/www/wordpress
chmod 700 /var/www/wordpress
/etc/init.d/apache2 restart