#!/bin/bash # Installs Überbringer behind nginx with a Let's Encrypt certificate. # # Usage: sudo ./install.sh 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 " 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 < "$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 < /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 < /etc/nginx/includes/letsencrypt-webroot location / { alias /var/www/$DOMAIN/; } EOT rm -f /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default cat < /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 < /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