AnyBot/deploy/sign-setup.sh

26 lines
1.4 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/sh
# 讓 AnyBot 的更新可以驗證來源(作者做一次):
# 之後你的每個 commit 都用 SSH 金鑰簽章;deploy/allowed_signers 記下公鑰。
# 別人第一次安裝時會記住這把公鑰,以後的更新不是它簽的就不裝(deploy/update.sh)。
#
# make sign-setup 用 ~/.ssh/id_ed25519.pub
# KEY=~/.ssh/別的.pub make sign-setup
#
# 換金鑰:把新公鑰加進 deploy/allowed_signers,用「舊」金鑰簽這個 commit 推出去,之後再改用新的。
set -eu
cd "$(dirname "$0")/.."
KEY=${KEY:-$HOME/.ssh/id_ed25519.pub}
[ -f "$KEY" ] || { echo "找不到公鑰:${KEY}(先 ssh-keygen -t ed25519,或用 KEY=… 指定)"; exit 1; }
# Only the key itself goes in the list: the comment (often an e-mail or a machine name) stays out.
pub=$(awk '{print $1 " " $2; exit}' "$KEY")
line="anybot namespaces=\"git\" $pub"
touch deploy/allowed_signers
grep -qxF "$line" deploy/allowed_signers || printf '%s\n' "$line" >>deploy/allowed_signers
git config gpg.format ssh
git config user.signingkey "$KEY"
git config commit.gpgsign true
git config gpg.ssh.allowedSignersFile "$(pwd)/deploy/allowed_signers"
echo "✓ 這個資料夾之後的 commit 都會簽章;公鑰記在 deploy/allowed_signers"
echo " 下一步:git add deploy/allowed_signers && git commit(這個 commit 本身就會被簽)再 push。"
echo " 確認:git log --show-signature -1"