trAvis - MANAGER
Edit File: wp_theme.sh
#!/bin/bash set -Ceuo pipefail ### vars PHP_VERSION="$1" SERVER_ID="$2" DOMAIN="$3" SUBNAME="" if [[ $# -ge 4 ]]; then SUBNAME="$4" fi if [[ $# -ge 5 ]]; then GLOBAL_OPTION="$5" else # GLOBAL_OPTION="--skip-themes --skip-plugins" GLOBAL_OPTION="" fi if [[ $# -ge 6 ]]; then OPTION="$6" else OPTION="list" fi PHP_PATH="/opt/php-${PHP_VERSION}/bin/php" WP_CLI_PATH="/usr/bin/wp" USER_WP_PATH="/home/${SERVER_ID}/${DOMAIN}/public_html${SUBNAME}" USER_WP_CONFIG="${USER_WP_PATH}/wp-config.php" ### functions function erroract(){ echo "$1" exit 1 } function warnact(){ echo "$1" exit 0 } ### MAIN { if [[ ${USER} = "root" ]]; then erroract "Script_Error: invalid exec user root." fi if [[ ${SERVER_ID} != "${USER}" ]]; then erroract "Script_Error: invalid argument SERVER_ID." fi ## PHPバージョン以外の入力値に相対パスが含まれていたらエラーメッセージと1を返す if [[ ${SERVER_ID} =~ .*\.\./.* || ${DOMAIN} =~ .*\.\./.* || ${SUBNAME} =~ .*\.\./.* || ${OPTION} =~ .*\.\./.* ]]; then erroract "Script_Error: invalid argument containing \"../\"." fi if [[ ! -f ${USER_WP_CONFIG} ]]; then warnact "Script_Warning: ${SERVER_ID}'s WordPress is not installed." fi cd "${USER_WP_PATH}" ## theme check が失敗したらエラーメッセージと1を返す ${PHP_PATH} ${WP_CLI_PATH} theme ${OPTION} ${GLOBAL_OPTION} --path="${USER_WP_PATH}" 2>&1 \ || erroract "Script_Error: wp-cli current Theme did not complete successfully." ## サブシェルで実行した出力結果に文字列を付与 } | awk -v user="${USER}" '{print "time:" strftime("%Y-%m-%dT%H:%M:%S%z") "\tuser:" user "\tpath:'"${USER_WP_PATH} "'" "\tmessage:" $0; fflush(); }'