trAvis - MANAGER
Edit File: wp_update_theme.sh
#!/bin/bash set -Ceuo pipefail ### vars PHP_VERSION="$1" SERVER_ID="$2" PACKAGE_SRC="$3" DOMAIN="$4" SUBNAME="" if [[ $# -ge 5 ]]; then SUBNAME="$5" 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} =~ .*\.\./.* || ${PACKAGE_SRC} =~ .*\.\./.* || ${DOMAIN} =~ .*\.\./.* || ${SUBNAME} =~ .*\.\./.* ]]; 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 install が失敗したらエラーメッセージと1を返す ${PHP_PATH} ${WP_CLI_PATH} theme install "${PACKAGE_SRC}" --path="${USER_WP_PATH}" --force 2>&1 \ || erroract "Script_Error: wp-cli 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(); }'