#!/bin/sh # แทน origin ที่อบไว้ในไฟล์ static (canonical / og:url / JSON-LD / sitemap / robots / ai.txt) # ใช้เมื่อ PUBLIC_ORIGIN ต่างจาก BAKED_ORIGIN เช่น deploy ขึ้นโดเมนใหม่หรือ preview หลายโดเมน # ไม่ตั้งค่า = ใช้ origin ที่อบมาแล้ว (ไม่มีอะไรเปลี่ยน) set -eu PUBLIC_ORIGIN="${PUBLIC_ORIGIN:-}" BAKED_ORIGIN="${BAKED_ORIGIN:-}" if [ -z "$PUBLIC_ORIGIN" ] || [ "$PUBLIC_ORIGIN" = "$BAKED_ORIGIN" ]; then echo "origin: ใช้ค่าที่อบมา ($BAKED_ORIGIN) — ไม่ต้องแทนที่" exit 0 fi DOC_ROOT=/usr/share/nginx/html changed=0 for f in $(find "$DOC_ROOT" -type f \( -name '*.html' -o -name '*.xml' -o -name '*.txt' \)); do if grep -qF "$BAKED_ORIGIN" "$f"; then sed -i "s|${BAKED_ORIGIN}|${PUBLIC_ORIGIN}|g" "$f" changed=$((changed + 1)) fi done echo "origin: แทนที่ ${BAKED_ORIGIN} → ${PUBLIC_ORIGIN} ใน ${changed} ไฟล์"