Files
blackwolf/tools/install-hooks.sh
T
2026-10-16 21:59:00 +08:00

28 lines
942 B
Bash
Executable File
Raw 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/sh
# 安装 git 钩子:提交后自动构建并上传网站。
# 用法:tools/install-hooks.sh
# 卸载:rm .git/hooks/post-commit(本脚本写入的内容带 "# blackwolf" 标记)
set -e
root=$(git rev-parse --show-toplevel)
hook="$root/.git/hooks/post-commit"
mkdir -p "$(dirname "$hook")"
cat > "$hook" <<'EOF'
#!/bin/sh
# blackwolf: 提交后自动部署(构建 + rsync 上传)
log="$(git rev-parse --show-toplevel)/.git/deploy.log"
echo "== $(date '+%F %T') post-commit deploy ==" >> "$log"
if make -s deploy >> "$log" 2>&1; then
echo "网站已更新(详见 .git/deploy.log)"
else
echo "网站部署失败,详见 .git/deploy.log" >&2
fi
EOF
chmod +x "$hook"
echo "已安装: $hook"
echo "以后 git commit 后会自动跑 make deploy(构建 + 上传)。"
echo "如需免密上传,请先把公钥装到服务器:"
echo " ssh-copy-id dwuser@drwater.net # 或手动追加 ~/.ssh/id_ed25519.pub"