mirror of
https://github.com/myvesta/vesta
synced 2025-08-21 05:44:08 -07:00
Create v-add-wordpress-admin
This commit is contained in:
parent
491ac6255c
commit
9cf91d5535
1 changed files with 75 additions and 0 deletions
75
bin/v-add-wordpress-admin
Normal file
75
bin/v-add-wordpress-admin
Normal file
|
@ -0,0 +1,75 @@
|
|||
#!/bin/bash
|
||||
# info: Add a WordPress admin user to a specific domain
|
||||
# options: DOMAIN USERNAME PASSWORD EMAIL
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
whoami=$(whoami)
|
||||
if [ "$whoami" != "root" ]; then
|
||||
echo "You must be root to execute this script"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Importing system environment
|
||||
source /etc/profile
|
||||
|
||||
SILENT_MODE=1
|
||||
|
||||
# Argument definition
|
||||
domain=$1
|
||||
username=$2
|
||||
password=$3
|
||||
email=$4
|
||||
|
||||
user=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
|
||||
USER=$user
|
||||
|
||||
# Includes
|
||||
source /usr/local/vesta/func/main.sh
|
||||
source /usr/local/vesta/func/domain.sh
|
||||
|
||||
if [ -z "$user" ]; then
|
||||
check_result $E_NOTEXIST "domain $domain doesn't exist"
|
||||
fi
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '4' "$#" 'DOMAIN USERNAME PASSWORD EMAIL'
|
||||
is_format_valid 'domain'
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
|
||||
if [ ! -d "/home/$user" ]; then
|
||||
echo "User doesn't exist";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ ! -d "/home/$user/web/$domain/public_html" ]; then
|
||||
echo "Domain doesn't exist";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# Check if WP CLI is installed and install it if not
|
||||
if ! command -v wp &> /dev/null; then
|
||||
echo "WP CLI is not installed. Installing..."
|
||||
wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp
|
||||
chmod +x /usr/local/bin/wp
|
||||
echo "WP CLI installed successfully."
|
||||
fi
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
cd /home/$USER/web/$domain/public_html
|
||||
sudo -u $USER wp user create $username $email --role=administrator --user_pass="$password"
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
exit 0;
|
Loading…
Add table
Add a link
Reference in a new issue