Follow the house shell conventions

Constants UPPER_SNAKE, mutable locals PascalCase, braced expansions
throughout, per Development/Coding conventions in the vault.
This commit is contained in:
fisher
2026-08-23 08:57:15 +00:00
parent 952de1ea8e
commit fc40facfc5
6 changed files with 131 additions and 108 deletions
+16 -16
View File
@@ -30,13 +30,13 @@ die() { printf '\n\033[31mERROR\033[0m %s\n' "$*" >&2; exit 1; }
info "Checking prerequisites"
for tool in python3 docker curl flock stdbuf; do
command -v "$tool" >/dev/null 2>&1 || die "required tool not found: ${tool}"
for Tool in python3 docker curl flock stdbuf; do
command -v "${Tool}" >/dev/null 2>&1 || die "required tool not found: ${Tool}"
done
ok "python3, docker, curl, flock, stdbuf"
WEBHOOK_BIN="${WEBHOOK_BIN:-$(command -v webhook || true)}"
[[ -n "$WEBHOOK_BIN" && -x "$WEBHOOK_BIN" ]] || die \
[[ -n "${WEBHOOK_BIN}" && -x "${WEBHOOK_BIN}" ]] || die \
"adnanh/webhook not found. Install it, or set WEBHOOK_BIN=/path/to/webhook.
Debian/Ubuntu: sudo apt install webhook
Or a release binary from https://github.com/adnanh/webhook/releases"
@@ -56,36 +56,36 @@ ok "host ${CD_HOST}, binding ${CD_BIND}:${CD_PORT}"
mapfile -t TARGETS < <("${REPO_ROOT}/bin/cd-target" list)
[[ ${#TARGETS[@]} -gt 0 ]] || die "no enabled targets for ${CD_HOST} in targets.json"
for target in "${TARGETS[@]}"; do
ok "target ${target}"
for Target in "${TARGETS[@]}"; do
ok "target ${Target}"
done
# ----------------------------------------------------------------- secrets ---
info "Checking the secrets file"
mkdir -p "$CONFIG_DIR"
chmod 700 "$CONFIG_DIR"
mkdir -p "${CONFIG_DIR}"
chmod 700 "${CONFIG_DIR}"
if [[ ! -f "$SECRETS_FILE" ]]; then
install -m 0600 "${REPO_ROOT}/secrets.env.example" "$SECRETS_FILE"
if [[ ! -f "${SECRETS_FILE}" ]]; then
install -m 0600 "${REPO_ROOT}/secrets.env.example" "${SECRETS_FILE}"
die "created a template at ${SECRETS_FILE}
Fill in one secret per repository, then re-run this installer.
The same value must be set as the Secret on the Gitea webhook."
fi
chmod 600 "$SECRETS_FILE"
chmod 600 "${SECRETS_FILE}"
ok "${SECRETS_FILE}"
# ------------------------------------------------------------------- hooks ---
info "Rendering hooks for ${CD_HOST}"
"${REPO_ROOT}/bin/cd-render-hooks" --output "$HOOKS_FILE" --secrets "$SECRETS_FILE"
"${REPO_ROOT}/bin/cd-render-hooks" --output "${HOOKS_FILE}" --secrets "${SECRETS_FILE}"
# ------------------------------------------------------------------ systemd --
info "Installing the user service"
mkdir -p "$SYSTEMD_DIR"
mkdir -p "${SYSTEMD_DIR}"
sed -e "s|@WEBHOOK_BIN@|${WEBHOOK_BIN}|g" \
-e "s|@HOOKS_FILE@|${HOOKS_FILE}|g" \
-e "s|@BIND@|${CD_BIND}|g" \
@@ -94,15 +94,15 @@ sed -e "s|@WEBHOOK_BIN@|${WEBHOOK_BIN}|g" \
ok "${SYSTEMD_DIR}/${UNIT_NAME}"
systemctl --user daemon-reload
systemctl --user enable "$UNIT_NAME" >/dev/null
systemctl --user restart "$UNIT_NAME"
systemctl --user enable "${UNIT_NAME}" >/dev/null
systemctl --user restart "${UNIT_NAME}"
ok "enabled and restarted"
# Survive logout, same as the other user services in this fleet.
loginctl enable-linger "$(whoami)" >/dev/null 2>&1 || true
sleep 1
systemctl --user is-active --quiet "$UNIT_NAME" \
systemctl --user is-active --quiet "${UNIT_NAME}" \
|| die "the service did not stay running:
systemctl --user status ${UNIT_NAME}
journalctl --user -u ${UNIT_NAME} -n 50 --no-pager"
@@ -120,7 +120,7 @@ printf ' %-28s %s\n' "Secret" "the matching value from ${SECRETS_FILE}"
echo
"${REPO_ROOT}/bin/cd-render-hooks" --list-urls \
--output "$HOOKS_FILE" --base-url "http://${CD_BIND}:${CD_PORT}" \
--output "${HOOKS_FILE}" --base-url "http://${CD_BIND}:${CD_PORT}" \
| sed 's/^/ /'
echo