summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@vps-18a7a2b7.vps.ovh.ca>2023-04-10 13:35:46 -0400
committerroot <root@vps-18a7a2b7.vps.ovh.ca>2023-04-10 13:35:46 -0400
commitd29e7f661ae2c8f761035e691b9b6d9f535b9e9d (patch)
tree6f7f27465f158b0f232f8a64475c837432ab1aad
parent21a80d889f8e6541b542d57c403005ebf664116e (diff)
refactorings
-rwxr-xr-xnew-wordpress-domain.sh77
1 files changed, 47 insertions, 30 deletions
diff --git a/new-wordpress-domain.sh b/new-wordpress-domain.sh
index 0781c71..13fa33a 100755
--- a/new-wordpress-domain.sh
+++ b/new-wordpress-domain.sh
@@ -3,44 +3,61 @@ TEMPLATE=ichimisushiandgrill.com
3OUTPUT=${1:-ichimisushi-thai.com} 3OUTPUT=${1:-ichimisushi-thai.com}
4SANITIZED=${OUTPUT//[-.]/_} 4SANITIZED=${OUTPUT//[-.]/_}
5DB_USER=$SANITIZED 5DB_USER=$SANITIZED
6TABLE_NAME=wordpress_$SANITIZED 6DB_NAME=wordpress_$SANITIZED
7 7
8PATH=$PWD:$PATH 8PATH=$PWD:$PATH
9 9
10have_database()
11{
12 mysql -ss -e "show databases like '${1//\'/\'\'}'" | (read match && [ "$match" ])
13}
14
10set -ex 15set -ex
11[ "$OUTPUT" != "$TEMPLATE" ] 16[ "$OUTPUT" != "$TEMPLATE" ]
12 17
13# Create new apache virtual host 18create_apache_vhost()
14if [ ! -e /etc/apache2/sites-enabled/$OUTPUT.conf ] 19{
15then 20 if [ ! -e /etc/apache2/sites-enabled/$OUTPUT.conf ]
16 [ -e /etc/apache2/sites-available/$TEMPLATE.conf ] 21 then
17 mkdir /srv/$OUTPUT /srv/$OUTPUT/public_html /srv/$OUTPUT/logs 22 [ -e /etc/apache2/sites-available/$TEMPLATE.conf ]
18 cd /etc/apache2/sites-available/ 23 mkdir /srv/$OUTPUT /srv/$OUTPUT/public_html /srv/$OUTPUT/logs
19 sed -e "s/$TEMPLATE/$OUTPUT/g" < "$TEMPLATE".conf > "$OUTPUT".conf 24 cd /etc/apache2/sites-available/
20 a2ensite $OUTPUT 25 sed -e "s/$TEMPLATE/$OUTPUT/g" < "$TEMPLATE".conf > "$OUTPUT".conf
21 systemctl reload apache2 26 a2ensite $OUTPUT
22fi 27 systemctl reload apache2
28 fi
29}
23 30
24# Install wordpress content to apache htdocs directory 31# Install wordpress content to apache htdocs directory
25if [ ! -e /srv/"$OUTPUT"/public_html/wordpress/wp-config.php ] 32install_wordpress_documents()
26then 33{
27 cd /srv/"$OUTPUT"/public_html 34 if [ ! -e /srv/"$OUTPUT"/public_html/wordpress/wp-config.php ]
28 curl https://wordpress.org/latest.tar.gz | tar -zx 35 then
29 cd wordpress 36 (
30 wp-conf.sh "$TABLE_NAME" "$DB_USER" > wp-config.php 37 cd /srv/"$OUTPUT"/public_html
31 38 curl https://wordpress.org/latest.tar.gz | tar -zx
32 chown www-data.www-data -R . 39 cd wordpress
33 chown nobody.nogroup wp-config.php 40 wp-conf.sh "$DB_NAME" "$DB_USER" > wp-config.php
34fi 41 chown www-data.www-data -R .
42 chown nobody.nogroup wp-config.php
43 )
44 fi
45}
35 46
36# Set up database 47create_database()
37if true 48{
38then 49 # Set up database
39 pwline=$(grep DB_PASSWORD /srv/$OUTPUT/public_html/wordpress/wp-config.php) 50 if ! have_database "$DB_NAME"
40 DB_PASSWORD=$(php -r "$pwline echo DB_PASSWORD;") 51 then
41 mysqladmin create "$TABLE_NAME" 52 pwline=$(grep DB_PASSWORD /srv/$OUTPUT/public_html/wordpress/wp-config.php)
42 mysql "$TABLE_NAME" <<END 53 DB_PASSWORD=$(php -r "$pwline echo DB_PASSWORD;")
43grant all privileges on \`$TABLE_NAME\`.* to "$DB_USER" identified by "$DB_PASSWORD"; 54 mysqladmin create "$DB_NAME"
55 mysql "$DB_NAME" <<END
56grant all privileges on \`$DB_NAME\`.* to "$DB_USER" identified by "$DB_PASSWORD";
44END 57END
45fi 58 fi
59}
46 60
61create_apache_vhost
62install_wordpress_documents
63create_database