#!/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" < 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/^/ /'