From 3e23ef2f580e792615c3db528594ec58e9a79842 Mon Sep 17 00:00:00 2001 From: Naokazu Terada Date: Tue, 28 Jul 2026 14:30:42 +0900 Subject: [PATCH] =?UTF-8?q?WordPress:=20=E3=82=B5=E3=82=A4=E3=83=88?= =?UTF-8?q?=E5=9B=BA=E6=9C=89=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E5=B7=AE?= =?UTF-8?q?=E3=81=97=E8=BE=BC=E3=82=80=E3=83=95=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit リポジトリ直下に .depinc-extra.sh があれば読み込み、そこで before_sync_extra / after_sync_extra を定義していれば標準処理のあとに呼ぶ。 背景: niwa-archives.org と branddesigncontest.com は、さくらで PHP バージョンを php.cgi で切り替えている都合上 php.cgi のパーミッション設定が必要で、そのために 標準版を使わず独自の .depinc.sh をリポジトリに持っていた。結果として 2024 年から 更新が止まり、メンテナンス画面もコアのバージョン照合も取りこぼしていた。 固有の設定を標準に持ち込まずに済ませつつ、標準の更新は自動で追従できるようにする。 フックを持たないサイトへの影響はない(ファイルが無ければ読み込まず、関数が 未定義なら呼ばない)。 Co-Authored-By: Claude Opus 5 --- .depignore | 1 + include-files/wordpress/.depinc.sh | 58 ++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/.depignore b/.depignore index 0517278..7b7cd2e 100644 --- a/.depignore +++ b/.depignore @@ -24,6 +24,7 @@ yarn.lock # github-deploy .depignore .depinc.sh +.depinc-extra.sh deploy.sh # for MODX diff --git a/include-files/wordpress/.depinc.sh b/include-files/wordpress/.depinc.sh index 438d77e..400861b 100644 --- a/include-files/wordpress/.depinc.sh +++ b/include-files/wordpress/.depinc.sh @@ -10,6 +10,26 @@ # - .htaccess / robots.txt / *.php の #DEP_*_RM / //DEP_*_RM マーカーを除去(後述の # 通り mtime を保存して差分転送を維持)。 # - rsync の場合のみ、同期後にパーミッションを設定する(FTP では実施不可のため skip)。 +# - サイト固有の処理を差し込むフックを提供する(後述)。 +# +# サイト固有の処理(フック): +# リポジトリ直下に `.depinc-extra.sh` があれば読み込む。そこで下記の関数を定義すると、 +# 標準処理のあとに呼ばれる。定義しなければ何も起きない。 +# +# before_sync_extra マーカー除去・メンテ ON のあと、同期の直前 +# after_sync_extra パーミッション設定のあと、同期の直後 +# +# _dep_ssh / _dep_lftp / $DEP_HOST_DIR など、本ファイルの関数・変数をそのまま使える。 +# +# 例)さくらで PHP バージョンを php.cgi で切り替えているサイト: +# +# # .depinc-extra.sh +# after_sync_extra(){ +# _dep_ssh "cd '$DEP_HOST_DIR' && find ./ -name php.cgi -exec chmod 705 {} \;" +# } +# +# 【必須】.depignore に `.depinc-extra.sh` を追加すること(サーバへ転送しないため)。 +# デフォルトの .depignore には追加済み。 # # 必要に応じて調整する環境変数: # DEP_WP_DIR WP コアのディレクトリ(HOST_DIR からの相対)。既定 "wp" @@ -33,6 +53,13 @@ DEP_WP_DIR="${DEP_WP_DIR:-wp}" _dep_maint_file="$DEP_HOST_DIR/$DEP_WP_DIR/.maintenance" +# サイト固有のフックを読み込む(無ければ何もしない)。 +# 本ファイルの関数を上書きしないよう、定義するのは *_extra 関数に限ること。 +if [ -f "./.depinc-extra.sh" ]; then + # shellcheck source=/dev/null + . "./.depinc-extra.sh" +fi + # lftp をワンショット実行(FTPS 設定を吸収) _dep_lftp(){ local opt="set ftp:ssl-allow off;" @@ -196,22 +223,31 @@ before_sync(){ done < <(grep -rlZ --exclude-dir=.git --include='*.php' \ -e "//DEP_REMOTE_RM " -e "//DEP_${branch}_RM " . 2>/dev/null) + # サイト固有の処理(.depinc-extra.sh で定義。無ければ何もしない) + type before_sync_extra >/dev/null 2>&1 && before_sync_extra + return 0 } after_sync(){ # パーミッション設定は SSH 前提。lftp(FTP) では実施できないため skip。 - [ "$DEP_COMMAND" = "lftp" ] && return 0 - - _dep_ssh " - cd '$DEP_HOST_DIR' - echo '--- Set Permissions -------------' - find ./ -type d -exec chmod 705 {} \; - find ./ -type f -exec chmod 604 {} \; - find ./ -name .htaccess -exec chmod 604 {} \; - find ./ -name wp-config.php -exec chmod 400 {} \; - echo '---------------------------------' - " + if [ "$DEP_COMMAND" != "lftp" ]; then + _dep_ssh " + cd '$DEP_HOST_DIR' + echo '--- Set Permissions -------------' + find ./ -type d -exec chmod 705 {} \; + find ./ -type f -exec chmod 604 {} \; + find ./ -name .htaccess -exec chmod 604 {} \; + find ./ -name wp-config.php -exec chmod 400 {} \; + echo '---------------------------------' + " + fi + + # サイト固有の処理(.depinc-extra.sh で定義。無ければ何もしない) + # lftp でも呼ぶ。SSH が使えない環境向けの処理を書けるようにするため。 + type after_sync_extra >/dev/null 2>&1 && after_sync_extra + + return 0 } # deploy.sh の EXIT trap から呼ばれ、成功・失敗・中断いずれでもメンテを解除する