Files
SupplierSystem/deploy/semaphore/install-on-h51.sh
T
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

86 lines
2.7 KiB
Bash

#!/usr/bin/env bash
# Bootstrap Semaphore on test-h51. Run as ubuntu with sudo.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
DEST="${SEMAPHORE_ROOT:-/opt/semaphore}"
if [[ "$(id -u)" -ne 0 ]]; then
exec sudo -E bash "$0" "$@"
fi
echo "==> Install docker if needed"
if ! command -v docker >/dev/null 2>&1; then
apt-get update -y
apt-get install -y docker.io docker-compose-v2 rsync
systemctl enable --now docker
fi
echo "==> Layout $DEST"
mkdir -p "$DEST"/{data,ssh,artifacts/frontend,ansible}
rsync -a --delete \
--exclude data --exclude ssh --exclude artifacts --exclude .env \
"$ROOT"/ "$DEST"/
if [[ ! -f "$DEST/.env" ]]; then
PASS="$(openssl rand -base64 18 | tr -d '/+=' | cut -c1-20)"
ENC="$(head -c32 /dev/urandom | base64 -w0 2>/dev/null || head -c32 /dev/urandom | base64)"
cat >"$DEST/.env" <<EOF
SEMAPHORE_ADMIN_PASSWORD=$PASS
SEMAPHORE_ACCESS_KEY_ENCRYPTION=$ENC
EOF
chmod 600 "$DEST/.env"
echo "Wrote $DEST/.env (admin password generated)"
fi
if [[ ! -f "$DEST/ssh/id_rsa" ]]; then
echo "ERROR: missing $DEST/ssh/id_rsa — copy deploy key before start"
exit 1
fi
chmod 600 "$DEST/ssh/id_rsa"
chown -R root:root "$DEST/ssh"
chmod 700 "$DEST/ssh"
echo "==> Fix data permissions (container uid 1001)"
mkdir -p "$DEST/data" "$DEST/artifacts/frontend"
chown -R 1001:0 "$DEST/data" "$DEST/artifacts"
chmod -R 0775 "$DEST/data" "$DEST/artifacts"
echo "==> Pull & start"
cd "$DEST"
if ! docker image inspect semaphoreui/semaphore:v2.13.4 >/dev/null 2>&1; then
if docker pull mirror.ccs.tencentyun.com/semaphoreui/semaphore:v2.13.4; then
docker tag mirror.ccs.tencentyun.com/semaphoreui/semaphore:v2.13.4 semaphoreui/semaphore:v2.13.4
else
docker compose --env-file .env pull
fi
fi
# ansible dir must be a git repo for file:// repository
if [[ ! -d "$DEST/ansible/.git" ]]; then
git -C "$DEST/ansible" init
git -C "$DEST/ansible" config user.email "ops@local"
git -C "$DEST/ansible" config user.name "ops"
git -C "$DEST/ansible" add -A
git -C "$DEST/ansible" commit -m "init playbooks" || true
fi
chown -R 1001:0 "$DEST/ansible" "$DEST/data" "$DEST/artifacts"
docker compose --env-file .env up -d
# avoid dubious ownership when container clones file:///ansible
docker exec -u root semaphore git config --global --add safe.directory '*' || true
docker exec -u 1001 semaphore git config --global --add safe.directory '*' || true
python3 "$DEST/bootstrap-project.py" || true
echo "==> Wait for HTTP"
for i in $(seq 1 40); do
if curl -sf "http://127.0.0.1:3010/api/ping" >/dev/null 2>&1 \
|| curl -sf "http://127.0.0.1:3010/" >/dev/null 2>&1; then
echo "Semaphore is up on :3010"
break
fi
sleep 2
done
echo "Admin user: admin"
echo "Password file: $DEST/.env"
grep SEMAPHORE_ADMIN_PASSWORD "$DEST/.env" | sed 's/^/ /'