2021-04-07 09:43:20 -07:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# wordpress-tools
|
|
|
|
# https://git.stack-source.com/msb/wordpress-tools
|
|
|
|
# MIT License Copyright (c) 2021 Matthew Saunders Brown
|
|
|
|
|
|
|
|
# require root
|
|
|
|
if [ "${EUID}" -ne 0 ]; then
|
|
|
|
echo "This script must be run as root"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
VHOST=$1
|
|
|
|
|
2021-04-14 18:45:57 -07:00
|
|
|
if [ ! -f /srv/www/$VHOST/html/wp-config.php ]; then
|
2021-04-07 09:43:20 -07:00
|
|
|
echo "Config file /srv/$VHOST/html/wp-config.php does not exist."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set username
|
|
|
|
VHOST_USER=$(stat -c '%U' /srv/$VHOST)
|
|
|
|
|
2021-04-14 18:45:13 -07:00
|
|
|
cd /srv/www/$VHOST/html/
|
2021-04-07 09:43:20 -07:00
|
|
|
DB_NAME=`wp --allow-root config get DB_NAME`
|
|
|
|
DB_USER=`wp --allow-root config get DB_USER`
|
|
|
|
DB_PASSWORD=`wp --allow-root config get DB_PASSWORD`
|
|
|
|
DB_HOST=`wp --allow-root config get DB_HOST`
|
|
|
|
|
|
|
|
#if [ $DB_HOST == '127.0.0.1' ]; then
|
|
|
|
# DB_HOST=localhost
|
|
|
|
#fi
|
|
|
|
|
|
|
|
if [ -d /var/lib/mysql/$DB_NAME ]; then
|
|
|
|
echo "NOTICE: $DB_NAME already exists"
|
|
|
|
echo " before proceeding do manual checks for db user"
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo mysqladmin create $DB_NAME
|
|
|
|
fi
|
|
|
|
echo mysql -e \"CREATE USER \'$DB_USER\'@\'$DB_HOST\' IDENTIFIED BY \'$DB_PASSWORD\'\;\"
|
|
|
|
echo mysql -e \"GRANT ALL PRIVILEGES ON $DB_NAME.* TO \'$DB_USER\'@\'$DB_HOST\'\;\"
|