Install behind Caddy instead of nginx and acme.sh
install.sh sets up a fresh Debian or Ubuntu host behind Caddy, installed from Caddy's apt repository, which obtains and renews the certificate itself. The site goes to /etc/caddy/uberbringer.caddy and the Caddyfile imports it; an edited Caddyfile only gains the import line. The result is validated as the caddy user, and both files are put back if Caddy rejects it. Caddy's body limit follows webserver.body_limit, and a larger body gets the daemon's 413 body_too_large JSON. A re-run upgrades the binary, the unit and Caddy and restarts the service. The script does not migrate hosts set up by the 0.1 script. The Docker image stays a proxy-free microservice behind the operator's own reverse proxy. The README credits the pre-refactor code, written without AI, and design.md records the persistent job store and image previews as deferred work. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4562f0cebb
commit
92dcacb3b9
7 files changed
+353
-278
No files matched your search
+207
-195
@@ -1,12 +1,15 @@
|
||||
#!/bin/bash
|
||||
# Installs Überbringer behind nginx with a Let's Encrypt certificate.
|
||||
# Installs Überbringer on a fresh Debian or Ubuntu host, behind Caddy, which
|
||||
# obtains and renews the TLS certificate itself. Ports 80 and 443 must be
|
||||
# free for Caddy.
|
||||
#
|
||||
# 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.
|
||||
# Re-running the script upgrades the binary, the systemd unit and Caddy,
|
||||
# rewrites Überbringer's Caddy site and restarts the service. It keeps the
|
||||
# config, an edited Caddyfile and any `systemctl edit uberbringer` drop-ins.
|
||||
set -euo pipefail
|
||||
|
||||
DOMAIN="${1:-}"
|
||||
@@ -22,26 +25,22 @@ SERVICE_USER=uberbringer
|
||||
# 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"
|
||||
UNIT_FILE=/usr/local/lib/systemd/system/uberbringer.service
|
||||
# The daemon's default webserver.body_limit, used when the config sets none.
|
||||
DEFAULT_BODY_LIMIT=4194304
|
||||
CADDYFILE=/etc/caddy/Caddyfile
|
||||
CADDY_SITE=/etc/caddy/uberbringer.caddy
|
||||
CADDY_LOG=/var/log/caddy/uberbringer-access.log
|
||||
CADDY_IMPORT="import $CADDY_SITE"
|
||||
CADDY_KEYRING=/usr/share/keyrings/caddy-stable-archive-keyring.gpg
|
||||
CADDY_SOURCES=/etc/apt/sources.list.d/caddy-stable.list
|
||||
CADDY_REPO=https://dl.cloudsmith.io/public/caddy/stable
|
||||
# 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." >&2
|
||||
@@ -53,13 +52,17 @@ if [[ -z "$DOMAIN" || -z "$ACME_EMAIL" || -z "$PRINTER_ADDRESS" ]]; then
|
||||
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.
|
||||
# The domain and the email go unquoted into the Caddy site file, and the
|
||||
# printer address into a TOML string, so each is limited to the characters
|
||||
# its kind of value needs.
|
||||
if [[ ! "$DOMAIN" =~ ^[A-Za-z0-9.-]+$ ]]; then
|
||||
echo "Invalid domain: $DOMAIN" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! "$ACME_EMAIL" =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+$ ]]; then
|
||||
echo "Invalid email address: $ACME_EMAIL" >&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
|
||||
@@ -112,31 +115,19 @@ detect_arch() {
|
||||
esac
|
||||
}
|
||||
|
||||
# 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..."
|
||||
install_base_packages() {
|
||||
info "Installing curl and gnupg..."
|
||||
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."
|
||||
apt-get install -y curl gnupg >> "$LOG" 2>&1 || fatal "apt-get install failed; see $LOG."
|
||||
|
||||
require nginx
|
||||
require curl
|
||||
require socat
|
||||
require sha256sum
|
||||
require systemctl
|
||||
require runuser
|
||||
}
|
||||
|
||||
# download_release fetches the release archive and checksums.txt into
|
||||
@@ -162,10 +153,12 @@ download_release() {
|
||||
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."
|
||||
[[ -f "$WORK_DIR/release/packaging/uberbringer.service" ]] ||
|
||||
fatal "$archive does not contain packaging/uberbringer.service."
|
||||
}
|
||||
|
||||
install_binary() {
|
||||
install_if_changed "$WORK_DIR/release/uberbringer" 0755 "$BIN"
|
||||
install -m 0755 "$WORK_DIR/release/uberbringer" "$BIN"
|
||||
# Run from its installed path: WORK_DIR may be on a noexec /tmp.
|
||||
info "Installed $("$BIN" version)"
|
||||
}
|
||||
@@ -205,157 +198,6 @@ EOT
|
||||
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() {
|
||||
debug "Installing the systemd unit from $UNIT_SRC..."
|
||||
|
||||
# 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
|
||||
|
||||
mkdir -p "$UNIT_DIR"
|
||||
install_if_changed "$UNIT_SRC" 0644 "$UNIT_FILE"
|
||||
|
||||
systemctl daemon-reload
|
||||
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() {
|
||||
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 >> "$LOG" 2>&1
|
||||
debug "Starting Nginx..."
|
||||
systemctl restart nginx
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
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..."
|
||||
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
|
||||
|
||||
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 $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;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
# write_initial_token saves the first bearer token to a root-only file instead
|
||||
@@ -374,6 +216,175 @@ write_initial_token() {
|
||||
debug "Wrote the first API token to $TOKEN_FILE."
|
||||
}
|
||||
|
||||
# install_service installs the unit and restarts the service, which reads its
|
||||
# config only at startup.
|
||||
install_service() {
|
||||
install -D -m 0644 "$WORK_DIR/release/packaging/uberbringer.service" "$UNIT_FILE"
|
||||
systemctl daemon-reload
|
||||
systemctl enable uberbringer >> "$LOG" 2>&1
|
||||
systemctl restart uberbringer
|
||||
}
|
||||
|
||||
# install_caddy installs or upgrades Caddy's Debian package from Caddy's
|
||||
# signed apt repository, as Caddy's install guide describes.
|
||||
install_caddy() {
|
||||
info "Installing Caddy from its apt repository..."
|
||||
# Optional helpers from Caddy's guide; gnupg and curl are what the steps
|
||||
# below need.
|
||||
apt-get install -y debian-keyring debian-archive-keyring apt-transport-https >> "$LOG" 2>&1 ||
|
||||
debug "Optional keyring packages are unavailable; continuing."
|
||||
curl -fsSL --proto '=https' --tlsv1.2 "$CADDY_REPO/gpg.key" |
|
||||
gpg --dearmor --yes -o "$CADDY_KEYRING" ||
|
||||
fatal "Couldn't fetch Caddy's signing key."
|
||||
curl -fsSL --proto '=https' --tlsv1.2 "$CADDY_REPO/debian.deb.txt" > "$CADDY_SOURCES" ||
|
||||
fatal "Couldn't fetch Caddy's apt source list."
|
||||
chmod o+r "$CADDY_KEYRING" "$CADDY_SOURCES"
|
||||
apt-get update >> "$LOG" 2>&1 || warn "apt-get update failed; trying the install anyway (see $LOG)."
|
||||
apt-get install -y caddy >> "$LOG" 2>&1 || fatal "Installing Caddy failed; see $LOG."
|
||||
require caddy
|
||||
}
|
||||
|
||||
# body_limit prints webserver.body_limit from the config, so Caddy accepts
|
||||
# exactly the request bodies the daemon does.
|
||||
body_limit() {
|
||||
local limit
|
||||
limit="$(awk '
|
||||
/^[ \t]*\[/ { section = $0; gsub(/[][ \t]/, "", section); next }
|
||||
section == "webserver" && /^[ \t]*body_limit[ \t]*=/ {
|
||||
sub(/^[^=]*=[ \t]*/, ""); sub(/[ \t#].*$/, ""); print; exit
|
||||
}' "$CONFIG")"
|
||||
limit="${limit//_/}"
|
||||
if [[ "$limit" =~ ^[0-9]+$ ]] && ((limit > 0)); then
|
||||
echo "$limit"
|
||||
else
|
||||
echo "$DEFAULT_BODY_LIMIT"
|
||||
fi
|
||||
}
|
||||
|
||||
# managed_caddyfile prints the Caddyfile this script writes. Once the
|
||||
# operator edits it, it no longer matches and is kept.
|
||||
managed_caddyfile() {
|
||||
printf '%s\n%s\n%s\n' \
|
||||
"# Written by Überbringer's install.sh. Your edits are kept: a re-run" \
|
||||
"# only adds the import below if it is missing." \
|
||||
"$CADDY_IMPORT"
|
||||
}
|
||||
|
||||
# caddyfile_is_package_default reports whether the Caddyfile is the caddy
|
||||
# package's file, unchanged, by the checksum dpkg recorded for it.
|
||||
caddyfile_is_package_default() {
|
||||
local packaged current
|
||||
packaged="$(dpkg-query -W -f='${Conffiles}\n' caddy 2> /dev/null |
|
||||
awk -v f="$CADDYFILE" '$1 == f { print $2; exit }' || true)"
|
||||
[[ -n "$packaged" ]] || return 1
|
||||
current="$(md5sum "$CADDYFILE" | awk '{ print $1 }')"
|
||||
[[ "$current" == "$packaged" ]]
|
||||
}
|
||||
|
||||
# validate_caddy checks the configuration as the caddy user, with its home,
|
||||
# so the files validation opens or creates are the caddy user's, as they are
|
||||
# for caddy.service.
|
||||
validate_caddy() {
|
||||
local home
|
||||
home="$(getent passwd caddy | cut -d: -f6)"
|
||||
runuser -u caddy -- env HOME="${home:-/var/lib/caddy}" \
|
||||
caddy validate --config "$CADDYFILE" --adapter caddyfile >> "$LOG" 2>&1
|
||||
}
|
||||
|
||||
# write_caddy_site writes Überbringer's site file and makes the Caddyfile
|
||||
# import it, then validates the result. If Caddy rejects it, both files are
|
||||
# put back as they were.
|
||||
write_caddy_site() {
|
||||
info "Configuring Caddy for $DOMAIN..."
|
||||
local backup="$WORK_DIR/caddy-backup"
|
||||
mkdir -p "$backup"
|
||||
if [[ -f "$CADDY_SITE" ]]; then cp -p "$CADDY_SITE" "$backup/site"; fi
|
||||
if [[ -f "$CADDYFILE" ]]; then cp -p "$CADDYFILE" "$backup/Caddyfile"; fi
|
||||
|
||||
install -d -o caddy -g caddy /var/log/caddy
|
||||
# Created as the caddy user's file before anything opens it.
|
||||
if [[ ! -e "$CADDY_LOG" ]]; then
|
||||
install -o caddy -g caddy -m 0640 /dev/null "$CADDY_LOG"
|
||||
fi
|
||||
|
||||
local limit
|
||||
limit="$(body_limit)"
|
||||
cat <<EOT > "$CADDY_SITE"
|
||||
# Written by Überbringer's install.sh, which rewrites it on every run.
|
||||
(uberbringer_headers) {
|
||||
header {
|
||||
Strict-Transport-Security "max-age=31536000; includeSubDomains"
|
||||
X-Frame-Options DENY
|
||||
X-Content-Type-Options nosniff
|
||||
Referrer-Policy no-referrer
|
||||
-Server
|
||||
}
|
||||
}
|
||||
|
||||
$DOMAIN {
|
||||
tls $ACME_EMAIL
|
||||
|
||||
request_body {
|
||||
# webserver.body_limit from $CONFIG, in bytes.
|
||||
max_size $limit
|
||||
}
|
||||
|
||||
reverse_proxy 127.0.0.1:8080 {
|
||||
# Überbringer trusts X-Real-IP from 127.0.0.1 for per-client rate limits.
|
||||
header_up X-Real-IP {remote_host}
|
||||
}
|
||||
|
||||
import uberbringer_headers
|
||||
|
||||
# Caddy refuses a body over max_size before Überbringer sees it, so the
|
||||
# refusal is the JSON error Überbringer would have sent.
|
||||
handle_errors 413 {
|
||||
import uberbringer_headers
|
||||
header Content-Type application/json
|
||||
header Cache-Control no-store
|
||||
respond \`{"error":"request body is too large","code":"body_too_large"}\` 413
|
||||
}
|
||||
|
||||
log {
|
||||
output file $CADDY_LOG
|
||||
}
|
||||
}
|
||||
EOT
|
||||
chmod 0644 "$CADDY_SITE"
|
||||
|
||||
# A missing Caddyfile, the package's untouched one and the one this
|
||||
# script wrote are replaced. An edited Caddyfile only gains the import
|
||||
# line, and keeps its owner and mode.
|
||||
if [[ ! -f "$CADDYFILE" ]] || cmp -s "$CADDYFILE" <(managed_caddyfile) || caddyfile_is_package_default; then
|
||||
if [[ -f "$CADDYFILE" ]] && ! cmp -s "$CADDYFILE" <(managed_caddyfile); then
|
||||
cp -p "$CADDYFILE" "$CADDYFILE.default"
|
||||
info "Replacing the package's default Caddyfile (kept as $CADDYFILE.default)..."
|
||||
fi
|
||||
managed_caddyfile > "$CADDYFILE"
|
||||
chmod 0644 "$CADDYFILE"
|
||||
elif ! grep -qxF "$CADDY_IMPORT" "$CADDYFILE"; then
|
||||
cp -p "$CADDYFILE" "$CADDYFILE.bak"
|
||||
printf '\n%s\n' "$CADDY_IMPORT" >> "$CADDYFILE"
|
||||
info "Added '$CADDY_IMPORT' to your $CADDYFILE (previous copy kept as $CADDYFILE.bak)."
|
||||
fi
|
||||
|
||||
if ! validate_caddy; then
|
||||
if [[ -f "$backup/site" ]]; then cp -p "$backup/site" "$CADDY_SITE"; else rm -f "$CADDY_SITE"; fi
|
||||
if [[ -f "$backup/Caddyfile" ]]; then cp -p "$backup/Caddyfile" "$CADDYFILE"; else rm -f "$CADDYFILE"; fi
|
||||
fatal "Caddy rejected the configuration, so $CADDYFILE and $CADDY_SITE were put back as they were (details in $LOG). Überbringer's site must be defined only in $CADDY_SITE."
|
||||
fi
|
||||
}
|
||||
|
||||
start_caddy() {
|
||||
systemctl enable caddy >> "$LOG" 2>&1
|
||||
if systemctl is-active --quiet caddy; then
|
||||
systemctl reload caddy || fatal "Reloading Caddy failed; see 'journalctl -u caddy'."
|
||||
else
|
||||
systemctl restart caddy || fatal "Caddy did not start; see 'journalctl -u caddy' (ports 80 and 443 must be free)."
|
||||
fi
|
||||
info "Caddy is requesting a certificate for $DOMAIN. If https://$DOMAIN does not answer within a minute, see 'journalctl -u caddy': the domain's DNS must point here, and ports 80 and 443 must be reachable."
|
||||
}
|
||||
|
||||
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."
|
||||
@@ -388,23 +399,24 @@ token_notice() {
|
||||
main() {
|
||||
info "Script loaded, starting the install process..."
|
||||
|
||||
install_packages
|
||||
install_base_packages
|
||||
|
||||
WORK_DIR="$(mktemp -d)"
|
||||
trap cleanup EXIT
|
||||
|
||||
# Nothing else is installed unless the release downloads and matches its
|
||||
# checksum.
|
||||
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
|
||||
issue_certificate
|
||||
install_reverse_proxy
|
||||
|
||||
install_caddy
|
||||
write_caddy_site
|
||||
start_caddy
|
||||
|
||||
info "Uberbringer service is now installed."
|
||||
info "Override unit settings with 'systemctl edit uberbringer'; drop-ins survive re-runs of this script."
|
||||
|
||||
Reference in new issue
Block a user