42 lines
1.0 KiB
Bash
Executable File
42 lines
1.0 KiB
Bash
Executable File
#!/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
|
|
|
|
if [ ! -f /srv/$VHOST/html/wp-config.php ]; then
|
|
echo "Config file /srv/$VHOST/html/wp-config.php does not exist."
|
|
exit
|
|
fi
|
|
|
|
# set username
|
|
VHOST_USER=$(stat -c '%U' /srv/$VHOST)
|
|
|
|
cd /srv/$VHOST/html/
|
|
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\'\;\"
|