Files
uberbringer/install.sh
T
57_WolveandClaude Opus 5.5 6502d9551d
CI / Lint, test and scan (push) Successful in 1m41s
Refactor to Go standards; add print queue and own ESC/POS library
Restructure the daemon to follow the project's Go coding standards and
expand its features.

Layout and tooling
- cmd/uberbringer/main.go is now thin; all logic lives under internal/.
- Module path is git.anomalous.dev/57_Wolve/uberbringer, go 1.26, every
  dependency upgraded, vendor/ removed.
- staticcheck, govulncheck and goimports pinned as go tools; add a
  Makefile, CI workflow, goreleaser v2 config and Alpine Dockerfile.

Features
- Background print queue with job status (GET /api/v1/jobs/:id), send
  retries with backoff, and graceful shutdown.
- New {"elements": [...]} job format on POST /api/v1/print. Breaking:
  replaces {"data": [...]}, and the response is now JSON 202.
- In-house ESC/POS library replacing justinmichaelvieira/escpos: sizes
  1-8, Font B, CODE39/CODE128, QR, banded raster images, DLE EOT status.
- UTF-8 text transcoded to CP437 (configurable) with word-aware wrapping.
- Images from URL or base64, scaled and dithered; URL fetches refuse
  internal addresses (SSRF guard).
- Fiber v3 HTTP server, TypeID (UUIDv7) job and request IDs, /healthz
  with live printer status, `secret` and `token` subcommands.

Fixes
- Jobs are validated before anything is sent; a failed printer dial no
  longer panics.
- Request logs never contain tokens; Sentry no longer receives the
  Authorization header or print contents.
- Rate limiting is per client behind nginx (X-Real-IP).
- install.sh writes the [printer] section, runs the service as a
  dedicated user and uses a current nginx TLS config.

config.toml is no longer tracked; start from configs/config.example.toml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 21:17:16 -06:00

243 lines
6.2 KiB
Bash

#!/bin/bash
# Installs Überbringer behind nginx with a Let's Encrypt certificate.
#
# Usage: sudo ./install.sh <domain> <acme-email> <printer-address>
set -euo pipefail
DOMAIN="${1:-}"
ACME_EMAIL="${2:-}"
PRINTER_ADDRESS="${3:-}"
LOG=/var/log/uberbringer-install.log
CONFIG_DIR=/etc/uberbringer
BIN=/usr/local/bin/uberbringer
SERVICE_USER=uberbringer
RELEASE_URL=https://git.anomalous.dev/57_Wolve/uberbringer/releases/download/latest
if [[ "$EUID" -ne 0 ]]; then
echo -e "\e[31m[FATAL]\e[39m This script must be run as root."
exit 1
fi
if [[ -z "$DOMAIN" || -z "$ACME_EMAIL" || -z "$PRINTER_ADDRESS" ]]; then
echo "Usage: $0 <domain> <acme-email> <printer-address>"
exit 1
fi
echo -e "\n\nINSTALL LOG FOR Uberbringer: $(date --rfc-3339=seconds)\n" >> "$LOG"
info() {
echo -e "\e[34m[INFO]\e[39m $1"
echo "[INFO] $1" >> "$LOG"
}
debug() {
if [[ -n "${DEBUG:-}" ]]; then
echo -e "\e[96m[DEBUG]\e[39m $1"
fi
echo "[DEBUG] $1" >> "$LOG"
}
fatal() {
echo -e "\e[31m[FATAL]\e[39m $1"
echo "[FATAL] $1" >> "$LOG"
exit 1
}
require() {
command -v "$1" > /dev/null 2>&1 || fatal "Couldn't find $1 - please install it and rerun the script."
}
detect_arch() {
case "$(uname -m)" in
x86_64) echo "amd64" ;;
aarch64 | arm64) echo "arm64" ;;
armv7l) echo "armv7" ;;
armv6l) echo "armv6" ;;
*) fatal "Unsupported architecture: $(uname -m)" ;;
esac
}
install_uberbringer_binary() {
local arch archive tmp
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"
}
create_service_user() {
if ! id "$SERVICE_USER" > /dev/null 2>&1; then
info "Creating system user $SERVICE_USER..."
useradd --system --no-create-home --shell /usr/sbin/nologin "$SERVICE_USER"
fi
}
write_config() {
mkdir -p "$CONFIG_DIR"
if [[ -f "$CONFIG_DIR/config.toml" ]]; then
info "Keeping existing $CONFIG_DIR/config.toml"
return
fi
info "Creating Uberbringer config..."
local secret
secret="$("$BIN" secret)"
cat <<EOT > "$CONFIG_DIR/config.toml"
[webserver]
bind_ip = "127.0.0.1"
port = 8080
[api]
secret = "$secret"
[printer]
address = "$PRINTER_ADDRESS"
EOT
chown root:"$SERVICE_USER" "$CONFIG_DIR/config.toml"
chmod 0640 "$CONFIG_DIR/config.toml"
}
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
[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
[Install]
WantedBy=multi-user.target
EOT
systemctl daemon-reload
systemctl enable uberbringer
debug "Starting Uberbringer Web Service..."
systemctl restart uberbringer
}
install_nginx() {
info "Configuring nginx..."
mkdir -p /etc/nginx/includes "/var/www/$DOMAIN"
cat <<EOT > /etc/nginx/includes/letsencrypt-webroot
location / {
alias /var/www/$DOMAIN/;
}
EOT
rm -f /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default
cat <<EOT > /etc/nginx/sites-available/default.conf
server {
listen 80;
listen [::]:80;
server_name $DOMAIN;
include includes/letsencrypt-webroot;
}
EOT
ln -sf /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
systemctl enable nginx
debug "Starting Nginx..."
systemctl restart nginx
}
install_acmesh() {
mkdir -p "/etc/letsencrypt/live/$DOMAIN"
info "Installing acme.sh..."
curl -fsSL https://get.acme.sh | sh -s email="$ACME_EMAIL"
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
info "Enabling acme.sh automatic upgrade..."
/root/.acme.sh/acme.sh --upgrade --auto-upgrade || true
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_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
error_log /var/log/nginx/uberbringer_error.log;
access_log /var/log/nginx/uberbringer_access.log;
client_max_body_size 4m;
location / {
proxy_redirect off;
proxy_set_header Host \$http_host;
# Uberbringer trusts X-Real-IP from 127.0.0.1 for per-client rate limits.
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 90;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy "no-referrer" always;
}
}
EOT
ln -sf /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf
nginx -t
debug "Reloading Nginx..."
systemctl reload nginx
}
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
require nginx
require curl
require socat
install_uberbringer_binary
create_service_user
write_config
install_service
install_nginx
install_acmesh
info "Uberbringer service is now installed."
echo -e "\e[34m[INFO]\e[39m API token: $("$BIN" token --config "$CONFIG_DIR/config.toml")"
}
main