Adopt norn's CI, release, API and docs practices; bare module path
Test / Lint, test and build (push) Successful in 3m17s
Test / Lint, test and build (push) Successful in 3m17s
Module
- The module path is now the bare "uberbringer"; imports read
uberbringer/internal/... The banner keeps the Gitea URL.
CI and releases
- Workflows move to .gitea/workflows: test.yml (every branch push:
gofmt, goimports, tidy, vet, staticcheck, race tests, goreleaser
snapshot), security.yml (govulncheck weekly and on main) and a hardened
release.yml (v* tags on main only, tags fetched, goreleaser pinned to
2.20.3). The broken labeler workflow is removed.
- go.mod pins toolchain go1.27.4, which fixes GO-2026-6859; workflows
check that the running Go matches it.
- .goreleaser.yaml: tidy check that never writes, reproducible file times,
prerelease: auto, a release header linking CHANGELOG.md, and archives
that ship CHANGELOG.md, the example config and the systemd unit.
- Makefile mirrors the CI gate; .dockerignore is an allowlist.
API and tests
- Every error answers {"error", "code", "details"} with a stable code from
server/errors.go; the framework's own error text is never sent.
- Panics and unexpected errors are logged and reported to Sentry once;
refusals are not logged as failures. /healthz sends no-store.
- TestRoutesConform requires auth, rate limiting and the body limit on
every /api/v1 route.
- Race-prone tests no longer rely on freed ports or sleeps; serve takes
an injected listener.
- The test config uses a placeholder secret instead of a real one.
Install and packaging
- install.sh resolves the latest release through the Gitea API, verifies
checksums, requests a certificate only when none exists, installs the
hardened packaging/uberbringer.service and writes the first token to a
0600 file instead of printing it. It is now executable in git.
Docs
- CLAUDE.md, CHANGELOG.md (0.2.0 with breaking changes and upgrade
steps), docs/design.md, and docs/plans/formatters.md for the planned
CP437 blocks, modules and ntfy printing. README updated throughout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
afcf96431f
commit
9b91109550
39 files changed
+3197
-433
No files matched your search
Regular → Executable
+234
-62
@@ -2,6 +2,11 @@
|
||||
# Installs Überbringer behind nginx with a Let's Encrypt certificate.
|
||||
#
|
||||
# Usage: sudo ./install.sh <domain> <acme-email> <printer-address>
|
||||
#
|
||||
# Installs the latest release. To install a given release instead, name its tag:
|
||||
# sudo UBERBRINGER_VERSION=v0.2.0 ./install.sh <domain> <acme-email> <printer-address>
|
||||
# Re-running the script upgrades the binary and the systemd unit, and keeps the
|
||||
# config, the certificate and any `systemctl edit uberbringer` drop-ins.
|
||||
set -euo pipefail
|
||||
|
||||
DOMAIN="${1:-}"
|
||||
@@ -10,17 +15,53 @@ PRINTER_ADDRESS="${3:-}"
|
||||
|
||||
LOG=/var/log/uberbringer-install.log
|
||||
CONFIG_DIR=/etc/uberbringer
|
||||
CONFIG="$CONFIG_DIR/config.toml"
|
||||
TOKEN_FILE="$CONFIG_DIR/initial-token"
|
||||
BIN=/usr/local/bin/uberbringer
|
||||
SERVICE_USER=uberbringer
|
||||
RELEASE_URL=https://git.anomalous.dev/57_Wolve/uberbringer/releases/download/latest
|
||||
# The vendor unit path for locally installed software. Units in
|
||||
# /etc/systemd/system take precedence over it, so operator changes belong in
|
||||
# drop-ins there.
|
||||
UNIT_DIR=/usr/local/lib/systemd/system
|
||||
UNIT_FILE="$UNIT_DIR/uberbringer.service"
|
||||
ETC_UNIT_FILE=/etc/systemd/system/uberbringer.service
|
||||
ACME=/root/.acme.sh/acme.sh
|
||||
CERT_DIR="/etc/letsencrypt/live/$DOMAIN"
|
||||
# Gitea resolves the tag "latest" to the newest release that is neither a
|
||||
# draft nor a prerelease.
|
||||
RELEASE_URL="https://git.anomalous.dev/57_Wolve/uberbringer/releases/download/${UBERBRINGER_VERSION:-latest}"
|
||||
# The checkout this script runs from, or empty when it is piped into bash.
|
||||
SCRIPT_DIR=""
|
||||
if [[ -n "${BASH_SOURCE[0]:-}" && -f "${BASH_SOURCE[0]}" ]]; then
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
fi
|
||||
|
||||
# Set when the binary, the unit or the config changed, so the service is
|
||||
# restarted only then.
|
||||
RESTART_NEEDED=0
|
||||
CONFIG_CREATED=0
|
||||
WORK_DIR=""
|
||||
UNIT_SRC=""
|
||||
|
||||
if [[ "$EUID" -ne 0 ]]; then
|
||||
echo -e "\e[31m[FATAL]\e[39m This script must be run as root."
|
||||
echo -e "\e[31m[FATAL]\e[39m This script must be run as root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$DOMAIN" || -z "$ACME_EMAIL" || -z "$PRINTER_ADDRESS" ]]; then
|
||||
echo "Usage: $0 <domain> <acme-email> <printer-address>"
|
||||
echo "Usage: $0 <domain> <acme-email> <printer-address>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The domain goes unquoted into nginx config and file paths, and the printer
|
||||
# address into a TOML string, so both are limited to host name and IP address
|
||||
# characters.
|
||||
if [[ ! "$DOMAIN" =~ ^[A-Za-z0-9.-]+$ ]]; then
|
||||
echo "Invalid domain: $DOMAIN" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! "$PRINTER_ADDRESS" =~ ^[A-Za-z0-9.:-]+$ ]]; then
|
||||
echo "Invalid printer address: $PRINTER_ADDRESS (expected an IP address or host name)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -31,6 +72,11 @@ info() {
|
||||
echo "[INFO] $1" >> "$LOG"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo -e "\e[33m[WARN]\e[39m $1"
|
||||
echo "[WARN] $1" >> "$LOG"
|
||||
}
|
||||
|
||||
debug() {
|
||||
if [[ -n "${DEBUG:-}" ]]; then
|
||||
echo -e "\e[96m[DEBUG]\e[39m $1"
|
||||
@@ -38,8 +84,10 @@ debug() {
|
||||
echo "[DEBUG] $1" >> "$LOG"
|
||||
}
|
||||
|
||||
# fatal writes to stderr so its message is not swallowed when it runs inside a
|
||||
# command substitution.
|
||||
fatal() {
|
||||
echo -e "\e[31m[FATAL]\e[39m $1"
|
||||
echo -e "\e[31m[FATAL]\e[39m $1" >&2
|
||||
echo "[FATAL] $1" >> "$LOG"
|
||||
exit 1
|
||||
}
|
||||
@@ -48,6 +96,12 @@ require() {
|
||||
command -v "$1" > /dev/null 2>&1 || fatal "Couldn't find $1 - please install it and rerun the script."
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "$WORK_DIR" ]]; then
|
||||
rm -rf "$WORK_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
detect_arch() {
|
||||
case "$(uname -m)" in
|
||||
x86_64) echo "amd64" ;;
|
||||
@@ -58,17 +112,62 @@ detect_arch() {
|
||||
esac
|
||||
}
|
||||
|
||||
install_uberbringer_binary() {
|
||||
local arch archive tmp
|
||||
# install_if_changed installs $1 as $3 with mode $2 unless $3 already has the
|
||||
# same content, and records that the service needs a restart.
|
||||
install_if_changed() {
|
||||
if cmp -s "$1" "$3"; then
|
||||
debug "$3 is unchanged."
|
||||
return
|
||||
fi
|
||||
install -m "$2" "$1" "$3"
|
||||
RESTART_NEEDED=1
|
||||
}
|
||||
|
||||
install_packages() {
|
||||
info "Installing curl, socat and nginx..."
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
# A broken third-party source makes the update fail even when the
|
||||
# packages below are installed or still installable, so only the install
|
||||
# is fatal.
|
||||
apt-get update >> "$LOG" 2>&1 || warn "apt-get update failed; trying the install anyway (see $LOG)."
|
||||
apt-get install -y nginx curl socat >> "$LOG" 2>&1 || fatal "apt-get install failed; see $LOG."
|
||||
|
||||
require nginx
|
||||
require curl
|
||||
require socat
|
||||
require sha256sum
|
||||
require systemctl
|
||||
}
|
||||
|
||||
# download_release fetches the release archive and checksums.txt into
|
||||
# WORK_DIR, verifies the archive and unpacks it there.
|
||||
download_release() {
|
||||
local arch archive
|
||||
arch="$(detect_arch)"
|
||||
archive="uberbringer_linux_${arch}.tar"
|
||||
tmp="$(mktemp -d)"
|
||||
trap 'rm -rf "$tmp"' RETURN
|
||||
|
||||
info "Downloading ${archive}..."
|
||||
curl -fsSL -o "$tmp/$archive" "$RELEASE_URL/$archive"
|
||||
tar -xf "$tmp/$archive" -C "$tmp"
|
||||
install -m 0755 "$tmp/uberbringer" "$BIN"
|
||||
info "Downloading ${archive} from ${RELEASE_URL}..."
|
||||
curl -fsSL -o "$WORK_DIR/checksums.txt" "$RELEASE_URL/checksums.txt" ||
|
||||
fatal "Couldn't download checksums.txt from $RELEASE_URL."
|
||||
curl -fsSL -o "$WORK_DIR/$archive" "$RELEASE_URL/$archive" ||
|
||||
fatal "Couldn't download $archive from $RELEASE_URL."
|
||||
|
||||
info "Verifying ${archive}..."
|
||||
# A leading * on the file name marks a binary-mode checksum line.
|
||||
awk -v f="$archive" '$2 == f || $2 == "*" f' "$WORK_DIR/checksums.txt" > "$WORK_DIR/archive.sha256"
|
||||
[[ -s "$WORK_DIR/archive.sha256" ]] || fatal "checksums.txt has no entry for $archive."
|
||||
(cd "$WORK_DIR" && sha256sum --check --strict --quiet archive.sha256) >> "$LOG" 2>&1 ||
|
||||
fatal "$archive does not match checksums.txt; nothing was installed."
|
||||
|
||||
mkdir "$WORK_DIR/release"
|
||||
tar -xf "$WORK_DIR/$archive" -C "$WORK_DIR/release"
|
||||
[[ -f "$WORK_DIR/release/uberbringer" ]] || fatal "$archive does not contain the uberbringer binary."
|
||||
}
|
||||
|
||||
install_binary() {
|
||||
install_if_changed "$WORK_DIR/release/uberbringer" 0755 "$BIN"
|
||||
# Run from its installed path: WORK_DIR may be on a noexec /tmp.
|
||||
info "Installed $("$BIN" version)"
|
||||
}
|
||||
|
||||
create_service_user() {
|
||||
@@ -80,14 +179,18 @@ create_service_user() {
|
||||
|
||||
write_config() {
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
if [[ -f "$CONFIG_DIR/config.toml" ]]; then
|
||||
info "Keeping existing $CONFIG_DIR/config.toml"
|
||||
if [[ -f "$CONFIG" ]]; then
|
||||
info "Keeping existing $CONFIG; edit printer.address there to change the printer."
|
||||
return
|
||||
fi
|
||||
info "Creating Uberbringer config..."
|
||||
local secret
|
||||
secret="$("$BIN" secret)"
|
||||
cat <<EOT > "$CONFIG_DIR/config.toml"
|
||||
# The config holds the API secret, so it is never readable by others, not
|
||||
# even between being written and being chmodded.
|
||||
(
|
||||
umask 027
|
||||
cat <<EOT > "$CONFIG"
|
||||
[webserver]
|
||||
bind_ip = "127.0.0.1"
|
||||
port = 8080
|
||||
@@ -98,39 +201,55 @@ write_config() {
|
||||
[printer]
|
||||
address = "$PRINTER_ADDRESS"
|
||||
EOT
|
||||
chown root:"$SERVICE_USER" "$CONFIG_DIR/config.toml"
|
||||
chmod 0640 "$CONFIG_DIR/config.toml"
|
||||
)
|
||||
chown root:"$SERVICE_USER" "$CONFIG"
|
||||
chmod 0640 "$CONFIG"
|
||||
CONFIG_CREATED=1
|
||||
RESTART_NEEDED=1
|
||||
}
|
||||
|
||||
# unit_source prints the path of the unit to install: the release archive's
|
||||
# copy, or for releases that do not ship one, the copy in this checkout.
|
||||
unit_source() {
|
||||
local candidate
|
||||
for candidate in "$WORK_DIR/release/packaging/uberbringer.service" \
|
||||
${SCRIPT_DIR:+"$SCRIPT_DIR/packaging/uberbringer.service"}; do
|
||||
if [[ -f "$candidate" ]]; then
|
||||
echo "$candidate"
|
||||
return
|
||||
fi
|
||||
done
|
||||
fatal "Neither the release archive nor this checkout has packaging/uberbringer.service."
|
||||
}
|
||||
|
||||
install_service() {
|
||||
info "Creating uberbringer.service..."
|
||||
cat <<EOT > /etc/systemd/system/uberbringer.service
|
||||
[Unit]
|
||||
Description=Uberbringer Daemon
|
||||
Wants=network-online.target
|
||||
After=network.target network-online.target
|
||||
debug "Installing the systemd unit from $UNIT_SRC..."
|
||||
|
||||
[Service]
|
||||
User=$SERVICE_USER
|
||||
Group=$SERVICE_USER
|
||||
WorkingDirectory=$CONFIG_DIR
|
||||
ExecStart=$BIN --config $CONFIG_DIR/config.toml
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
LimitNOFILE=4096
|
||||
NoNewPrivileges=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
PrivateTmp=true
|
||||
# A full unit in /etc shadows the packaged one. One with this Description
|
||||
# is an installer-generated copy rather than an operator's override, so it
|
||||
# is moved aside; any other file there is left alone with a warning.
|
||||
if [[ -f "$ETC_UNIT_FILE" ]] && grep -qx 'Description=Uberbringer Daemon' "$ETC_UNIT_FILE"; then
|
||||
info "Replacing the unit in $ETC_UNIT_FILE with $UNIT_FILE (old copy kept as $ETC_UNIT_FILE.bak)..."
|
||||
# Disabling first removes the wants symlink that points at the old path.
|
||||
systemctl disable uberbringer >> "$LOG" 2>&1
|
||||
mv "$ETC_UNIT_FILE" "$ETC_UNIT_FILE.bak"
|
||||
RESTART_NEEDED=1
|
||||
elif [[ -e "$ETC_UNIT_FILE" ]]; then
|
||||
warn "$ETC_UNIT_FILE overrides $UNIT_FILE; remove it to use the packaged unit."
|
||||
fi
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOT
|
||||
mkdir -p "$UNIT_DIR"
|
||||
install_if_changed "$UNIT_SRC" 0644 "$UNIT_FILE"
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable uberbringer
|
||||
debug "Starting Uberbringer Web Service..."
|
||||
systemctl restart uberbringer
|
||||
systemctl enable uberbringer >> "$LOG" 2>&1
|
||||
if [[ "$RESTART_NEEDED" -eq 1 ]]; then
|
||||
debug "Restarting Uberbringer Web Service..."
|
||||
systemctl restart uberbringer
|
||||
else
|
||||
debug "Binary, unit and config are unchanged; starting Uberbringer only if it is stopped..."
|
||||
systemctl start uberbringer
|
||||
fi
|
||||
}
|
||||
|
||||
install_nginx() {
|
||||
@@ -156,34 +275,55 @@ server {
|
||||
EOT
|
||||
|
||||
ln -sf /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
|
||||
systemctl enable nginx
|
||||
systemctl enable nginx >> "$LOG" 2>&1
|
||||
debug "Starting Nginx..."
|
||||
systemctl restart nginx
|
||||
}
|
||||
|
||||
install_acmesh() {
|
||||
mkdir -p "/etc/letsencrypt/live/$DOMAIN"
|
||||
# issue_certificate gets a certificate only when none is installed yet;
|
||||
# renewals are left to the cron job acme.sh installs.
|
||||
issue_certificate() {
|
||||
if [[ -s "$CERT_DIR/fullchain.pem" && -s "$CERT_DIR/privkey.pem" ]]; then
|
||||
info "Keeping the existing certificate in $CERT_DIR; acme.sh's cron job renews it."
|
||||
return
|
||||
fi
|
||||
|
||||
info "Installing acme.sh..."
|
||||
curl -fsSL https://get.acme.sh | sh -s email="$ACME_EMAIL"
|
||||
if [[ ! -x "$ACME" ]]; then
|
||||
info "Installing acme.sh..."
|
||||
curl -fsSL https://get.acme.sh | sh -s email="$ACME_EMAIL"
|
||||
|
||||
info "Enabling acme.sh automatic upgrade..."
|
||||
"$ACME" --upgrade --auto-upgrade || true
|
||||
fi
|
||||
|
||||
info "Issuing SSL certificate..."
|
||||
/root/.acme.sh/acme.sh --issue -w "/var/www/$DOMAIN" \
|
||||
--keypath "/etc/letsencrypt/live/$DOMAIN/privkey.pem" \
|
||||
--fullchainpath "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" \
|
||||
-d "$DOMAIN" --reloadcmd "systemctl reload nginx" --force
|
||||
local rc=0
|
||||
"$ACME" --issue --server letsencrypt -w "/var/www/$DOMAIN" -d "$DOMAIN" || rc=$?
|
||||
# 2 means acme.sh already holds a certificate for the domain that is not
|
||||
# due for renewal; --install-cert below copies it into place.
|
||||
if [[ "$rc" -ne 0 && "$rc" -ne 2 ]]; then
|
||||
fatal "acme.sh could not issue a certificate for $DOMAIN (exit code $rc)."
|
||||
fi
|
||||
|
||||
info "Enabling acme.sh automatic upgrade..."
|
||||
/root/.acme.sh/acme.sh --upgrade --auto-upgrade || true
|
||||
mkdir -p "$CERT_DIR"
|
||||
# acme.sh records these paths and the reload command, and reuses them when
|
||||
# its cron job renews the certificate.
|
||||
"$ACME" --install-cert -d "$DOMAIN" \
|
||||
--key-file "$CERT_DIR/privkey.pem" \
|
||||
--fullchain-file "$CERT_DIR/fullchain.pem" \
|
||||
--reloadcmd "systemctl reload nginx"
|
||||
}
|
||||
|
||||
install_reverse_proxy() {
|
||||
info "Configuring the HTTPS reverse proxy..."
|
||||
cat <<EOT > /etc/nginx/sites-available/reverse-proxy.conf
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
server_name $DOMAIN;
|
||||
|
||||
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
|
||||
ssl_certificate $CERT_DIR/fullchain.pem;
|
||||
ssl_certificate_key $CERT_DIR/privkey.pem;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_prefer_server_ciphers off;
|
||||
@@ -218,25 +358,57 @@ EOT
|
||||
systemctl reload nginx
|
||||
}
|
||||
|
||||
# write_initial_token saves the first bearer token to a root-only file instead
|
||||
# of printing it, so it does not end up in terminal scrollback or the log. It
|
||||
# runs right after the config is created, because a re-run after a later step
|
||||
# failed keeps that config and writes no token.
|
||||
write_initial_token() {
|
||||
if [[ "$CONFIG_CREATED" -ne 1 ]]; then
|
||||
return
|
||||
fi
|
||||
rm -f "$TOKEN_FILE"
|
||||
(
|
||||
umask 077
|
||||
"$BIN" token --config "$CONFIG" > "$TOKEN_FILE"
|
||||
)
|
||||
debug "Wrote the first API token to $TOKEN_FILE."
|
||||
}
|
||||
|
||||
token_notice() {
|
||||
if [[ "$CONFIG_CREATED" -eq 1 ]]; then
|
||||
info "The first API token is in $TOKEN_FILE (readable by root only). Copy it to your client, then delete the file."
|
||||
return
|
||||
fi
|
||||
if [[ -s "$TOKEN_FILE" ]]; then
|
||||
warn "$TOKEN_FILE still holds the first API token; delete it once your client has it."
|
||||
fi
|
||||
info "Issue API tokens with: $BIN token --config $CONFIG --subject <client>"
|
||||
}
|
||||
|
||||
main() {
|
||||
info "Script loaded, starting the install process..."
|
||||
|
||||
info "Installing curl, socat and nginx..."
|
||||
apt-get install -y nginx curl socat > /dev/null 2>&1
|
||||
install_packages
|
||||
|
||||
require nginx
|
||||
require curl
|
||||
require socat
|
||||
WORK_DIR="$(mktemp -d)"
|
||||
trap cleanup EXIT
|
||||
|
||||
install_uberbringer_binary
|
||||
download_release
|
||||
# Resolved first, so a missing unit stops the script before any of
|
||||
# Uberbringer's files are installed.
|
||||
UNIT_SRC="$(unit_source)"
|
||||
install_binary
|
||||
create_service_user
|
||||
write_config
|
||||
write_initial_token
|
||||
install_service
|
||||
install_nginx
|
||||
install_acmesh
|
||||
issue_certificate
|
||||
install_reverse_proxy
|
||||
|
||||
info "Uberbringer service is now installed."
|
||||
echo -e "\e[34m[INFO]\e[39m API token: $("$BIN" token --config "$CONFIG_DIR/config.toml")"
|
||||
info "Override unit settings with 'systemctl edit uberbringer'; drop-ins survive re-runs of this script."
|
||||
token_notice
|
||||
}
|
||||
|
||||
main
|
||||
Reference in new issue
Block a user