#!/bin/bash # info: Run WP CLI command for a specific domain # options: DOMAIN WP_CLI_COMMAND #----------------------------------------------------------# # 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 wp_command=${@:2} 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 # #----------------------------------------------------------# VERBOSE_MODE=1 check_args '2' "$#" 'DOMAIN WP_CLI_COMMAND' is_format_valid 'domain' is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" is_object_unsuspended 'web' 'DOMAIN' "$domain" if [ ! -d "/home/$user" ]; then # echo "User doesn't exist"; exit 1; fi if [ ! -f "/home/$user/web/$domain/public_html/wp-config.php" ]; then echo 'Please install WordPress first.' exit 1; fi 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 wpcli="/usr/local/bin/wp" if [ -f "/usr/local/bin/wp-cli/php/boot-fs.php" ]; then wpcli="/usr/local/bin/wp-cli/php/boot-fs.php" COLUMNS=$(/usr/bin/env stty size 2>/dev/null | awk '{print $2}') echo $COLUMNS > /usr/local/bin/wp-cli/COLUMNS fi mkdir -p /home/$user/.wp-cli chown $user:$user /home/$user/.wp-cli if [ -z "$PHP" ]; then phpver=$(/usr/local/vesta/bin/v-get-php-version-of-domain "$domain") else phpver=$PHP fi #----------------------------------------------------------# # Action # #----------------------------------------------------------# cd /home/$USER/web/$domain/public_html sudo -u $USER /usr/bin/php$phpver -d disable_functions=pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,exec,system,passthru,shell_exec,proc_open,popen -d open_basedir=/home/$user/web/$domain:/home/$user/.wp-cli:/home/$user/tmp:/usr/local/bin $wpcli --path=/home/$user/web/$domain/public_html/ $wp_command 2>/home/$user/web/$domain/wp-cli-error.log return_code=$? if [ -f "/usr/local/bin/wp-cli/COLUMNS" ]; then rm /usr/local/bin/wp-cli/COLUMNS fi # echo "WP CLI: Done." # echo "To see Warning/Error log: " # echo "cat /home/$user/web/$domain/wp-cli-error.log" #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# exit $return_code;