Files
homepage/tools/deploy.sh

26 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 官网统一部署脚本:bump 静态资源版本号(击穿浏览器缓存)+ 同步双服务器
# 用法: bash tools/deploy.sh
set -euo pipefail
cd "$(dirname "$0")/.."
STAMP=$(date "+%Y%m%d%H%M")
# bump 资源版本参数:HTML 更新(no-cache)会带新 URL,旧缓存自然失效
python3 - "$STAMP" <<'PYEOF'
import re, sys
stamp = sys.argv[1]
path = 'index.html'
html = open(path, encoding='utf-8').read()
# 正则一次性规范化:无论已有无版本参数,统一替换为当前时间戳
html = re.sub(r'assets/css/style\.css(?:\?v=\d+)?\d*', 'assets/css/style.css?v=' + stamp, html)
html = re.sub(r'assets/js/main\.js(?:\?v=\d+)?\d*', 'assets/js/main.js?v=' + stamp, html)
open(path, 'w', encoding='utf-8').write(html)
PYEOF
echo "[deploy] 版本号 ${STAMP},同步公网 + 局域网"
# 注意:assets 不带尾斜杠(带斜杠会把目录拍平,曾导致整站 404)
rsync -a --delete index.html assets ubuntu3:/var/www/shashann-homepage/
rsync -a --delete index.html assets ubuntu:/home/ubuntu/homepage-site/
echo "[deploy] 完成: https://www.shashann.com/ 与 https://192.168.51.66/homepage/"