sites

Source for the daat.foo sites
git clone https://git.daat.foo/sites.git
Log | Files | Refs | Submodules

commit 85876f6b6688bd01265259940ff05b4f349c3185
parent a5d2d14adc9f3b7894922fd1215ef70f65353ee3
Author: cowmonk <cowmonk@based.pt>
Date:   Tue,  1 Dec 2026 19:53:57 -0700

inv.daat.foo: add invidious deployment

Docker compose setup for inv.daat.foo: themed invidious image,
companion and postgres, behind lighttpd basic auth on port 8300.
Secrets (.env) are generated by install.sh and never tracked; the
unifont is copied from the searxng install at install time.

Diffstat:
Ainv.daat.foo/.dockerignore | 5+++++
Ainv.daat.foo/.gitignore | 3+++
Ainv.daat.foo/Dockerfile | 16++++++++++++++++
Ainv.daat.foo/compose.yaml | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainv.daat.foo/init-invidious-db.sh | 12++++++++++++
Ainv.daat.foo/install.sh | 193+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainv.daat.foo/lighttpd.conf | 25+++++++++++++++++++++++++
Ainv.daat.foo/terminal.css | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 422 insertions(+), 0 deletions(-)

diff --git a/inv.daat.foo/.dockerignore b/inv.daat.foo/.dockerignore @@ -0,0 +1,5 @@ +* +!Dockerfile +!terminal.css +!daat-unifont.otf +!init-invidious-db.sh diff --git a/inv.daat.foo/.gitignore b/inv.daat.foo/.gitignore @@ -0,0 +1,3 @@ +.env +.env.* +daat-unifont.otf diff --git a/inv.daat.foo/Dockerfile b/inv.daat.foo/Dockerfile @@ -0,0 +1,16 @@ +FROM quay.io/invidious/invidious@sha256:90115ee1781332e988d357249fd2b2460244a8ef380a0c0772ad7fbe1318427f AS upstream + +FROM upstream AS web +USER root +COPY terminal.css /tmp/terminal.css +COPY daat-unifont.otf /invidious/assets/css/daat-unifont.otf +RUN printf '\n' >> /invidious/assets/css/default.css \ + && cat /tmp/terminal.css >> /invidious/assets/css/default.css \ + && rm /tmp/terminal.css +USER invidious + +FROM docker.io/library/postgres:14 AS db +WORKDIR / +COPY --from=upstream /invidious/config/sql/ /config/sql/ +COPY init-invidious-db.sh /docker-entrypoint-initdb.d/init-invidious-db.sh +RUN chmod 0755 /docker-entrypoint-initdb.d/init-invidious-db.sh diff --git a/inv.daat.foo/compose.yaml b/inv.daat.foo/compose.yaml @@ -0,0 +1,76 @@ +name: daat-invidious + +services: + invidious: + build: + context: . + target: web + restart: unless-stopped + ports: + - "127.0.0.1:8300:3000" + environment: + INVIDIOUS_CONFIG: | + db: + dbname: invidious + user: invidious + password: "${INV_DB_PASSWORD:?run install.sh}" + host: db + port: 5432 + check_tables: true + domain: inv.daat.foo + external_port: 443 + https_only: true + hmac_key: "${INV_HMAC_KEY:?run install.sh}" + invidious_companion: + - private_url: http://companion:8282/companion + invidious_companion_key: "${INV_COMPANION_KEY:?run install.sh}" + login_enabled: false + registration_enabled: false + statistics_enabled: false + popular_enabled: false + default_user_preferences: + dark_mode: dark + default_home: "" + feed_menu: [] + local: true + depends_on: + db: + condition: service_healthy + companion: + condition: service_started + security_opt: + - no-new-privileges:true + + companion: + image: quay.io/invidious/invidious-companion@sha256:292d889ff6d4cb31970cd35ea9eea8b249dc8c1dc3c66b3ad1b9c4fd0ffb62d1 + restart: unless-stopped + environment: + SERVER_SECRET_KEY: "${INV_COMPANION_KEY:?run install.sh}" + volumes: + - companion-cache:/var/tmp/youtubei.js + cap_drop: + - ALL + read_only: true + security_opt: + - no-new-privileges:true + + db: + build: + context: . + target: db + restart: unless-stopped + environment: + POSTGRES_DB: invidious + POSTGRES_USER: invidious + POSTGRES_PASSWORD: "${INV_DB_PASSWORD:?run install.sh}" + volumes: + - postgres-data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 3s + timeout: 5s + retries: 30 + +volumes: + postgres-data: + companion-cache: diff --git a/inv.daat.foo/init-invidious-db.sh b/inv.daat.foo/init-invidious-db.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -eou pipefail + +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channels.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/videos.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channel_videos.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/users.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/session_ids.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql diff --git a/inv.daat.foo/install.sh b/inv.daat.foo/install.sh @@ -0,0 +1,193 @@ +#!/bin/sh +set -eu +umask 077 + +project=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P) +cd "$project" +host=inv.daat.foo +port=8300 +compose_file="$project/compose.yaml" +secrets="$project/.env" +font=/usr/local/searxng/searxng-src/searx/static/fonts/unifont-18.0.01.otf +lighttpd_dir=/etc/lighttpd +main_config="$lighttpd_dir/lighttpd.conf" +vhost_config="$lighttpd_dir/$host.conf" +include_line="include \"$vhost_config\"" +cert_dir="$lighttpd_dir/certs/$host" +acme_home=/root/.acme.sh +acme="$acme_home/acme.sh" +auth_file="$lighttpd_dir/auth/searxng.htpasswd" +webroot=/var/www/acme + +fail() { + printf 'inv: %s\n' "$*" >&2 + exit 1 +} + +if [ "${1:-}" = --check ]; then + INV_DB_PASSWORD=check INV_HMAC_KEY=check INV_COMPANION_KEY=check \ + docker compose --env-file /dev/null -f "$compose_file" config --quiet + printf '%s\n' 'Compose configuration is valid.' + exit 0 +fi +case "$#:${1:-}" in + 0:) mode=install ;; + 1:--proxy-only) mode=proxy ;; + *) fail 'usage: install.sh [--check | --proxy-only]' ;; +esac +if [ "$(id -u)" -ne 0 ]; then + exec doas "$project/install.sh" "$@" +fi + +exec 9>/run/lock/daat-invidious.lock +flock -n 9 || fail 'another install is running' +test -s "$auth_file" || fail "the SearXNG password file is missing or empty: $auth_file" +test -d "$webroot/.well-known/acme-challenge" || fail "ACME webroot is missing: $webroot" +rc-service lighttpd status >/dev/null || fail 'start lighttpd first' + +if grep -Fxq "$include_line" "$main_config"; then + cmp -s "$project/lighttpd.conf" "$vhost_config" || + fail "the installed vhost differs from $project/lighttpd.conf" +else + if [ -e "$vhost_config" ] || grep -Fq "\"$host\"" "$main_config"; then + fail "an existing lighttpd configuration for $host needs to be reviewed" + fi +fi + +prepare_secrets() { + if [ ! -e "$secrets" ]; then + db_password=$(openssl rand -hex 32) + hmac_key=$(openssl rand -hex 32) + companion_key=$(openssl rand -hex 8) + ( + set -C + printf 'INV_DB_PASSWORD=%s\nINV_HMAC_KEY=%s\nINV_COMPANION_KEY=%s\n' \ + "$db_password" "$hmac_key" "$companion_key" > "$secrets" + ) + elif grep -Eq '^INV_COMPANION_KEY=[a-f0-9]{64}$' "$secrets"; then + companion_key=$(openssl rand -hex 8) + migrated_secrets=$(mktemp "$project/.env.XXXXXXXX") + if ! sed "s/^INV_COMPANION_KEY=[a-f0-9]\\{64\\}$/INV_COMPANION_KEY=$companion_key/" \ + "$secrets" > "$migrated_secrets" || ! mv -f "$migrated_secrets" "$secrets"; then + rm -f "$migrated_secrets" + fail 'could not update the Companion key' + fi + printf '%s\n' 'Replaced the old Companion key with a 16-character key.' + fi + chmod 600 "$secrets" + unset INV_DB_PASSWORD INV_HMAC_KEY INV_COMPANION_KEY +} + +compose() { + docker compose --env-file "$secrets" -f "$compose_file" "$@" +} + +certificate_ready() { + [ -s "$cert_dir/privkey.pem" ] && + openssl x509 -in "$cert_dir/fullchain.pem" -noout -checkend 86400 >/dev/null 2>&1 && + openssl x509 -in "$cert_dir/fullchain.pem" -noout -checkhost "$host" | + grep -Fq 'does match certificate' +} + +setup_certificate() { + if certificate_ready && grep -Fxq "$include_line" "$main_config"; then + return + fi + + if [ ! -x "$acme" ]; then + acme_checkout="$project/../acme.sh/acme.sh" + test -f "$acme_checkout" || fail "install acme.sh under $acme_home first" + install -d -m 0700 "$acme_home" + install -m 0700 "$acme_checkout" "$acme" + fi + if ! certificate_ready; then + printf 'Requesting the TLS certificate for %s\n' "$host" + cert_status=0 + "$acme" --home "$acme_home" --issue --server letsencrypt \ + -d "$host" --keylength ec-256 -w "$webroot" || cert_status=$? + [ "$cert_status" -eq 0 ] || [ "$cert_status" -eq 2 ] || + fail "certificate issuance failed for $host" + fi + + install -d -m 0700 "$cert_dir" + touch "$cert_dir/fullchain.pem" "$cert_dir/privkey.pem" + chmod 600 "$cert_dir/fullchain.pem" "$cert_dir/privkey.pem" + "$acme" --home "$acme_home" --install-cronjob + "$acme" --home "$acme_home" --install-cert -d "$host" --ecc \ + --fullchain-file "$cert_dir/fullchain.pem" --key-file "$cert_dir/privkey.pem" \ + --reloadcmd 'if grep -Fxq "include \"/etc/lighttpd/inv.daat.foo.conf\"" /etc/lighttpd/lighttpd.conf; then rc-service lighttpd restart; fi' + certificate_ready || fail "the installed certificate is not valid for $host" +} + +http_code() { + curl --noproxy '*' -sS --max-time 5 -o /dev/null -w '%{http_code}' \ + --resolve "$host:443:127.0.0.1" --resolve "$host:80:127.0.0.1" "$1" +} + +check_proxy() { + [ "$(http_code "https://$host/")" = 401 ] && + [ "$(http_code "https://$host/css/default.css")" = 401 ] && + [ "$(http_code "https://$host/api/v1/search?q=test")" = 401 ] && + [ "$(http_code "https://$host/videoplayback")" = 401 ] && + [ "$(http_code "http://$host/")" = 403 ] +} + +publish_proxy() { + if grep -Fxq "$include_line" "$main_config"; then + check_proxy || fail "check the login and TLS configuration for $host" + return + fi + + previous_config=$(mktemp "$lighttpd_dir/.pre-invidious.XXXXXXXX") + candidate_config=$(mktemp "$lighttpd_dir/.with-invidious.XXXXXXXX") + cp -p "$main_config" "$previous_config" + cp -p "$main_config" "$candidate_config" + printf '\n%s\n' "$include_line" >> "$candidate_config" + install -m 0644 "$project/lighttpd.conf" "$vhost_config" + if ! lighttpd -tt -f "$candidate_config"; then + rm -f "$previous_config" "$candidate_config" "$vhost_config" + fail 'lighttpd rejected the Invidious vhost' + fi + mv -f "$candidate_config" "$main_config" + if rc-service lighttpd restart; then + attempts=0 + until check_proxy; do + attempts=$((attempts + 1)) + [ "$attempts" -lt 10 ] || break + sleep 1 + done + if [ "$attempts" -lt 10 ]; then + printf 'Previous lighttpd configuration saved in %s\n' "$previous_config" + return + fi + fi + + mv -f "$previous_config" "$main_config" + rm -f "$vhost_config" + rc-service lighttpd restart || fail 'the previous config was restored, but lighttpd could not start' + fail 'TLS or login verification failed, and the previous lighttpd configuration was restored' +} + +backend_ready() { + curl --noproxy '*' -fsS --max-time 5 "http://127.0.0.1:$port/css/default.css" 2>/dev/null | + grep -Fq -- '--inv-amber:' +} + +if [ "$mode" = install ]; then + test -r "$font" || fail "the SearXNG Unifont file is missing: $font" + docker info --format '{{.ServerVersion}}' >/dev/null + prepare_secrets + install -m 0644 "$font" "$project/daat-unifont.otf" + compose up -d --build --wait --wait-timeout 120 + attempts=0 + until backend_ready; do + attempts=$((attempts + 1)) + [ "$attempts" -lt 30 ] || fail 'Invidious did not serve its theme, check docker compose logs' + sleep 2 + done +else + backend_ready || fail 'the themed Invidious backend is not answering on localhost' +fi +setup_certificate +publish_proxy +printf 'Open https://%s/ and use your SearXNG login.\n' "$host" diff --git a/inv.daat.foo/lighttpd.conf b/inv.daat.foo/lighttpd.conf @@ -0,0 +1,25 @@ +$HTTP["host"] == "inv.daat.foo" { + ssl.pemfile = "/etc/lighttpd/certs/inv.daat.foo/fullchain.pem" + ssl.privkey = "/etc/lighttpd/certs/inv.daat.foo/privkey.pem" + + $HTTP["scheme"] == "https" { + auth.backend = "htpasswd" + auth.backend.htpasswd.userfile = "/etc/lighttpd/auth/searxng.htpasswd" + auth.require = ( + "" => ( + "method" => "basic", + "realm" => "daat video", + "require" => "valid-user" + ) + ) + proxy.server = ( + "" => (( "host" => "127.0.0.1", "port" => 8300 )) + ) + } + + $HTTP["scheme"] == "http" { + $HTTP["url"] !~ "^/[.]well-known/acme-challenge/[A-Za-z0-9_-]+$" { + url.access-deny = ( "" ) + } + } +} diff --git a/inv.daat.foo/terminal.css b/inv.daat.foo/terminal.css @@ -0,0 +1,92 @@ +@font-face { font-family: "DAAT Unifont"; + src: url("/css/daat-unifont.otf") format("opentype"); + font-display: swap; } + +.dark-theme { color-scheme: dark; + --inv-bg: #000; + --inv-panel: #080807; + --inv-text: #e6e2d7; + --inv-muted: #a8a8a0; + --inv-rule: #49412f; + --inv-amber: #f1c766; + --inv-bright: #ffe29b; } + +body.dark-theme { font-family: "DAAT Unifont", monospace; + font-size: 16px; + line-height: 1.5; + color: var(--inv-text); + background: var(--inv-bg); } +.dark-theme .pure-g [class*="pure-u"], +.dark-theme :where(input, select, textarea, button) + { font-family: inherit; } +.dark-theme :focus-visible { outline: 1px solid var(--inv-bright); + outline-offset: 2px; } + +.dark-theme #contents { box-sizing: border-box; + width: min(88rem, 100%); + padding-inline: clamp(.75rem, 2vw, 2rem); } +.dark-theme .navbar { margin: 0 0 1.5rem; + padding: .85rem 0; + row-gap: .65rem; + border-bottom: 1px dashed var(--inv-rule); } +.dark-theme .index-link.pure-menu-heading { display: inline-block; + padding: .32rem .65rem; + border: 1px solid var(--inv-amber); + background: var(--inv-panel); + color: var(--inv-amber); + text-transform: none; } +.dark-theme .user-field .pure-menu-heading { color: var(--inv-amber); } +.dark-theme .searchbar .pure-form { align-items: center; + gap: .4rem; } +.dark-theme .searchbar fieldset { min-width: 0; } +.dark-theme .searchbar #searchbox { box-sizing: border-box; + margin: 0; + padding: .55rem .75rem; + min-height: 2.75rem; + color: var(--inv-text); + background: var(--inv-panel); + border: 1px solid var(--inv-amber); + border-radius: 0; } +.dark-theme .searchbar #searchbox::placeholder { color: var(--inv-muted); } +.dark-theme .searchbar #searchbutton { color: var(--inv-amber); + cursor: pointer; } + +.dark-theme a, +.dark-theme .simulated_a { color: var(--inv-amber); } +.dark-theme a:hover, +.dark-theme .simulated_a:hover { color: var(--inv-bright); + text-decoration: underline; } +.dark-theme hr { border: 0; + border-bottom: 1px dashed var(--inv-rule); } +.dark-theme .video-card-row { border-bottom: 1px dashed var(--inv-rule); + padding-bottom: .85rem; } +.dark-theme .thumbnail, +.dark-theme .error-card { border: 1px solid var(--inv-rule); + border-radius: 0; } +.dark-theme :where(.video-data, time), +.dark-theme footer { color: var(--inv-muted); } +.dark-theme footer { border-top: 1px dashed var(--inv-rule); + background: var(--inv-bg); } +.dark-theme footer a { color: var(--inv-muted); } + +.dark-theme .pure-form input:not([type="hidden"]), +.dark-theme .pure-form select, +.dark-theme .pure-form textarea, +.dark-theme .pure-button { color: var(--inv-text); + background: var(--inv-panel); + border: 1px solid var(--inv-rule); + border-radius: 0; + box-shadow: none; } +.dark-theme .pure-button:hover, +.dark-theme .pure-button:focus { color: var(--inv-bg); + background: var(--inv-amber); } +.dark-theme .video-js { --primary-color: #f1c766; } +.dark-theme .video-js .vjs-big-play-button { border: 1px solid var(--inv-amber); + border-radius: 0; + color: var(--inv-amber); + background: var(--inv-panel); } + +@media (max-width: 48rem) { + .dark-theme .navbar { margin-bottom: 1rem; } + .dark-theme .searchbar { padding-inline: 0; } +}