diff --git a/lazylibrarian/data/config/config.ini b/lazylibrarian/data/config/config.ini new file mode 100644 index 000000000..62c731bf9 --- /dev/null +++ b/lazylibrarian/data/config/config.ini @@ -0,0 +1,31 @@ +[General] +ebook_dir = /downloads/books +audio_dir = /downloads/audiobooks +download_dir = /downloads/complete,/downloads/complete/books,/downloads/complete/audiobooks,/downloads/complete/magazines,/downloads/complete/comics + +[WebServer] +http_proxy = 1 + +[TRANSMISSION] +transmission_host = transmission_server_1 +transmission_port = 9091 +transmission_base = /transmission +transmission_dir = /downloads/complete +transmission_label = books,audiobooks,magazines,comics + +[QBITTORRENT] +qbittorrent_host = qbittorrent_server_1 +qbittorrent_port = 8080 +qbittorrent_dir = /downloads/complete + +[SABnzbd] +sab_host = sabnzbd_web_1 +sab_port = 8080 + +[Magazines] +mag_dest_folder = /downloads/magazines/$Title/$IssueDate +mag_relative = 0 + +[Comics] +comic_dest_folder = /downloads/comics/$Title/$Issue +comic_relative = 0 diff --git a/lazylibrarian/docker-compose.yml b/lazylibrarian/docker-compose.yml new file mode 100644 index 000000000..0873a7649 --- /dev/null +++ b/lazylibrarian/docker-compose.yml @@ -0,0 +1,16 @@ +services: + app_proxy: + environment: + APP_HOST: lazylibrarian_server_1 + APP_PORT: 5299 + + server: + image: ghcr.io/linuxserver/lazylibrarian:c537b374-ls413@sha256:a2ddcd3a1cbde4c263bfd4634818a3066ef5f4a62480cf41df1096d71f80f9bb + restart: on-failure + stop_grace_period: 1m + environment: + - PUID=1000 + - PGID=1000 + volumes: + - ${APP_DATA_DIR}/data/config:/config + - ${UMBREL_ROOT}/data/storage/downloads:/downloads diff --git a/lazylibrarian/hooks/pre-start b/lazylibrarian/hooks/pre-start new file mode 100755 index 000000000..6f14e3f56 --- /dev/null +++ b/lazylibrarian/hooks/pre-start @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +set -euo pipefail + +APP_DIR="${APP_DATA_DIR:-$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")}" +DATA_DIR="${APP_DATA_ROOT:-${APP_DIR}/data}" + +# Current umbrelOS releases include python3. This block uses only Python's +# standard library, so it has no third-party Python dependencies. +# +# Do not create or chown folders in Umbrel's shared Downloads storage here. +# umbrelOS provisions that storage, and LazyLibrarian runs as UID/GID 1000 +# and creates its required subdirectories with its default 0755 permissions. +python3 - "${APP_DIR}" "${DATA_DIR}" "${UMBREL_ROOT}" <<'PY' +import configparser +import os +from pathlib import Path +import stat +import sys +import tempfile + +app_data_dir = Path(sys.argv[1]) +data_dir = Path(sys.argv[2]) +umbrel_root = Path(sys.argv[3]) +config_path = data_dir / "config/config.ini" +torrent_flag = app_data_dir / "TORRENT_CLIENT_CONFIGURED_BY_UMBREL" +sabnzbd_flag = app_data_dir / "SABNZBD_CONFIGURED_BY_UMBREL" + +installed_apps = { + app + for app in ("transmission", "qbittorrent", "sabnzbd") + if (umbrel_root / "app-data" / app / "umbrel-app.yml").is_file() +} + +if not config_path.is_file(): + print(f"{config_path} does not exist; skipping downloader setup.", file=sys.stderr) + sys.exit(0) + +config = configparser.RawConfigParser(strict=False) +try: + config.read(config_path) +except configparser.Error as error: + print(f"Unable to read {config_path}: {error}", file=sys.stderr) + sys.exit(0) + + +def section(name): + for existing in config.sections(): + if existing.casefold() == name.casefold(): + return existing + config.add_section(name) + return name + + +def enabled(section_name, prefix): + target = section(section_name) + return any( + key.casefold().startswith(prefix) + and value.strip().casefold() in {"1", "true", "yes", "on"} + for key, value in config.items(target) + ) + + +changed = False + + +def set_value(section_name, key, value, *, only_if_empty=False): + global changed + target = section(section_name) + if only_if_empty and config.get(target, key, fallback="").strip(): + return + if config.get(target, key, fallback=None) != value: + config.set(target, key, value) + changed = True + + +mark_torrent_configured = False +if not torrent_flag.exists(): + if enabled("TORRENT", "tor_downloader_"): + mark_torrent_configured = True + else: + torrent_downloaders = { + "transmission": "tor_downloader_transmission", + "qbittorrent": "tor_downloader_qbittorrent", + } + installed_torrent_downloaders = [ + downloader for downloader in torrent_downloaders if downloader in installed_apps + ] + if len(installed_torrent_downloaders) == 1: + downloader = installed_torrent_downloaders[0] + set_value("TORRENT", torrent_downloaders[downloader], "1") + mark_torrent_configured = True + +mark_sabnzbd_configured = False +if not sabnzbd_flag.exists(): + if enabled("USENET", "nzb_downloader_"): + mark_sabnzbd_configured = True + elif "sabnzbd" in installed_apps: + sabnzbd_section = section("SABnzbd") + api_key = config.get(sabnzbd_section, "sab_api", fallback="").strip() + try: + sabnzbd_config = ( + umbrel_root / "app-data/sabnzbd/data/config/sabnzbd.ini" + ).read_text() + if not api_key: + for line in sabnzbd_config.splitlines(): + key, separator, value = line.partition("=") + if separator and key.strip() == "api_key": + api_key = value.strip() + break + except OSError: + pass + if api_key: + set_value("USENET", "nzb_downloader_sabnzbd", "1") + set_value("SABnzbd", "sab_api", api_key, only_if_empty=True) + mark_sabnzbd_configured = True + +if changed: + original = config_path.stat() + with tempfile.NamedTemporaryFile( + "w", + dir=config_path.parent, + delete=False, + ) as temporary: + config.write(temporary) + temporary_path = Path(temporary.name) + os.chmod(temporary_path, stat.S_IMODE(original.st_mode)) + os.chown(temporary_path, original.st_uid, original.st_gid) + os.replace(temporary_path, config_path) + +if mark_torrent_configured: + torrent_flag.touch() +if mark_sabnzbd_configured: + sabnzbd_flag.touch() +PY diff --git a/lazylibrarian/umbrel-app.yml b/lazylibrarian/umbrel-app.yml new file mode 100644 index 000000000..4ed64f923 --- /dev/null +++ b/lazylibrarian/umbrel-app.yml @@ -0,0 +1,76 @@ +manifestVersion: 1 +id: lazylibrarian +storage: + dataRoot: data +category: media +name: LazyLibrarian +version: "c537b374" +tagline: Manage and automate your digital reading library +description: >- + LazyLibrarian is a self-hosted collection manager for ebooks, audiobooks, magazines, and comics. Follow authors, track wanted titles, search for releases, and organize your digital reading library. + + + 🛠️ SETUP INSTRUCTIONS + + + **1. Install a download client** + + + Install Transmission, qBittorrent, or SABnzbd from the Umbrel App Store. LazyLibrarian comes with their connection details pre-filled. + + + If you have one torrent client installed, it is selected automatically. If you have both Transmission and qBittorrent installed, choose your preferred client in LazyLibrarian's Downloaders settings. + + + **2. Add providers** + + + Add providers in LazyLibrarian so it can search for releases. To use Prowlarr, add its Torznab or Newznab feed URLs as providers in LazyLibrarian. + + + **Where files are stored** + + + LazyLibrarian organizes your library inside Umbrel's shared Downloads folder: + + + - Ebooks: `Downloads/books` + + - Audiobooks: `Downloads/audiobooks` + + - Magazines: `Downloads/magazines` + + - Comics: `Downloads/comics` + + + Completed downloads are read from `Downloads/complete`. + + + **Access and security** + + + LazyLibrarian is protected by Umbrel authentication. If you expose it outside Umbrel's protected app proxy, enable LazyLibrarian's own authentication in its Interface settings. +releaseNotes: "" + +developer: LazyLibrarian +website: https://lazylibrarian.gitlab.io/ +dependencies: [] +repo: https://gitlab.com/LazyLibrarian/LazyLibrarian +support: https://gitlab.com/LazyLibrarian/LazyLibrarian/-/issues + +port: 5299 +gallery: + - 1.webp + - 2.webp + - 3.webp + - 4.webp +path: "/home" + +defaultUsername: "" +defaultPassword: "" + +permissions: + - STORAGE_DOWNLOADS + +submitter: nrempel +submission: https://github.com/getumbrel/umbrel-apps/pull/5855