diff options
author | root <root@vps-18a7a2b7.vps.ovh.ca> | 2023-04-10 13:35:46 -0400 |
---|---|---|
committer | root <root@vps-18a7a2b7.vps.ovh.ca> | 2023-04-10 13:35:46 -0400 |
commit | d29e7f661ae2c8f761035e691b9b6d9f535b9e9d (patch) | |
tree | 6f7f27465f158b0f232f8a64475c837432ab1aad | |
parent | 21a80d889f8e6541b542d57c403005ebf664116e (diff) |
refactorings
-rwxr-xr-x | new-wordpress-domain.sh | 77 |
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 | |||
3 | OUTPUT=${1:-ichimisushi-thai.com} | 3 | OUTPUT=${1:-ichimisushi-thai.com} |
4 | SANITIZED=${OUTPUT//[-.]/_} | 4 | SANITIZED=${OUTPUT//[-.]/_} |
5 | DB_USER=$SANITIZED | 5 | DB_USER=$SANITIZED |
6 | TABLE_NAME=wordpress_$SANITIZED | 6 | DB_NAME=wordpress_$SANITIZED |
7 | 7 | ||
8 | PATH=$PWD:$PATH | 8 | PATH=$PWD:$PATH |
9 | 9 | ||
10 | have_database() | ||
11 | { | ||
12 | mysql -ss -e "show databases like '${1//\'/\'\'}'" | (read match && [ "$match" ]) | ||
13 | } | ||
14 | |||
10 | set -ex | 15 | set -ex |
11 | [ "$OUTPUT" != "$TEMPLATE" ] | 16 | [ "$OUTPUT" != "$TEMPLATE" ] |
12 | 17 | ||
13 | # Create new apache virtual host | 18 | create_apache_vhost() |
14 | if [ ! -e /etc/apache2/sites-enabled/$OUTPUT.conf ] | 19 | { |
15 | then | 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 |
22 | fi | 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 |
25 | if [ ! -e /srv/"$OUTPUT"/public_html/wordpress/wp-config.php ] | 32 | install_wordpress_documents() |
26 | then | 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 |
34 | fi | 41 | chown www-data.www-data -R . |
42 | chown nobody.nogroup wp-config.php | ||
43 | ) | ||
44 | fi | ||
45 | } | ||
35 | 46 | ||
36 | # Set up database | 47 | create_database() |
37 | if true | 48 | { |
38 | then | 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;") |
43 | grant all privileges on \`$TABLE_NAME\`.* to "$DB_USER" identified by "$DB_PASSWORD"; | 54 | mysqladmin create "$DB_NAME" |
55 | mysql "$DB_NAME" <<END | ||
56 | grant all privileges on \`$DB_NAME\`.* to "$DB_USER" identified by "$DB_PASSWORD"; | ||
44 | END | 57 | END |
45 | fi | 58 | fi |
59 | } | ||
46 | 60 | ||
61 | create_apache_vhost | ||
62 | install_wordpress_documents | ||
63 | create_database | ||