Files
ezarr/setup.sh
dtoro 92aa9b4c22
Some checks failed
Check running / run (push) Has been cancelled
Allow splitting config, downloads and media paths via .env
Adds optional CONFIG_DIR, DOWNLOADS_DIR and MEDIA_DIR env variables so
users can spread configs, downloads and media across different drives
without restructuring ROOT_DIR. Each falls back to its ROOT_DIR-based
default when left empty, so existing setups keep working unchanged.

The -arr services (sonarr, radarr, lidarr, mylar3) now use a single
${DOWNLOADS_DIR}:/data parent bind with a ${MEDIA_DIR}:/data/media
overlay. This preserves TRaSH's single-/data-mount semantics inside
the container (hardlinks still work on one filesystem) while letting
the host-side media tree live wherever the user wants.

README documents the new variables, the generated folder structure,
recommended storage layouts, and the same-filesystem requirement for
hardlinks between downloads and media.
2026-04-17 10:40:44 +02:00

89 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
# Set up your .env file BEFORE running this script!!!
# export all variables from .env
set -a
source .env
set +a
# This is always going to complain about UID being a read-only variable.
# However that is not a problem and it's necessary for UID to be defined in the .env so that docker-compose.yml can take it.
# Reminder to set the UID variable in .env if you haven't already. It needs to be the user you want to run docker as. Find what it should be by running "id -u" from that user's shell.
# Resolve location overrides. If the user didn't set CONFIG_DIR / DOWNLOADS_DIR / MEDIA_DIR in .env,
# fall back to the ROOT_DIR-based defaults (which mirror what docker-compose.yml.sample uses).
ROOT_DIR=${ROOT_DIR:-.}
CONFIG_DIR=${CONFIG_DIR:-${ROOT_DIR}/config}
DOWNLOADS_DIR=${DOWNLOADS_DIR:-${ROOT_DIR}/data}
MEDIA_DIR=${MEDIA_DIR:-${ROOT_DIR}/data/media}
# NOTE on hardlinks: Sonarr/Radarr/etc. perform hardlinks and atomic moves from DOWNLOADS_DIR into
# MEDIA_DIR. This only works if both paths sit on the SAME filesystem. If you've split them across
# different drives or mounts, operations will silently fall back to copying.
# Make users and group
sudo useradd sonarr -u $SONARR_UID
sudo useradd radarr -u $RADARR_UID
sudo useradd lidarr -u $LIDARR_UID
sudo useradd mylar -u $MYLAR_UID
sudo useradd prowlarr -u $PROWLARR_UID
sudo useradd qbittorrent -u $QBITTORRENT_UID
sudo useradd jackett -u $JACKETT_UID
sudo useradd overseerr -u $OVERSEERR_UID
sudo useradd plex -u $PLEX_UID
sudo useradd sabnzbd -u $SABNZBD_UID
sudo useradd jellyseerr -u $JELLYSEERR_UID
sudo useradd bazarr -u $BAZARR_UID
sudo useradd audiobookshelf -u $AUDIOBOOKSHELF_UID
sudo groupadd mediacenter -g $MEDIACENTER_GID
# Adds current user to the mediacenter group. This is recommended so that you can still have access to files inside the ezarr folder structure for manual control.
# This is way better than just doing everything as root, especially on NFS shares. Also some services run as the default user anyway (Jellyfin, Tautulli).
sudo usermod -a -G mediacenter $USER
# When you add the user to the group the changes don't take effect immediately.
# You can force them by running "sudo newgrp mediacenter" but that won't always work and it's better to just reboot after the script finishes running.
# adds all the service users to the group
sudo usermod -a -G mediacenter sonarr
sudo usermod -a -G mediacenter radarr
sudo usermod -a -G mediacenter lidarr
sudo usermod -a -G mediacenter mylar
sudo usermod -a -G mediacenter prowlarr
sudo usermod -a -G mediacenter qbittorrent
sudo usermod -a -G mediacenter jackett
sudo usermod -a -G mediacenter overseerr
sudo usermod -a -G mediacenter plex
sudo usermod -a -G mediacenter sabnzbd
sudo usermod -a -G mediacenter jellyseerr
sudo usermod -a -G mediacenter bazarr
sudo usermod -a -G mediacenter audiobookshelf
# Make directories
sudo mkdir -pv ${CONFIG_DIR}/{sonarr,radarr,lidarr,mylar,prowlarr,qbittorrent,jackett,audiobookshelf,overseerr,plex,jellyfin,tautulli,sabnzbd,jellyseerr,bazarr}-config
sudo mkdir -pv ${DOWNLOADS_DIR}/{torrents,usenet}/{tv,movies,music,books,comics,audiobooks,podcasts}
sudo mkdir -pv ${MEDIA_DIR}/{tv,movies,music,books,comics,audiobooks,podcasts,audiobookshelf-metadata}
# Set permissions
sudo chmod -R 775 ${DOWNLOADS_DIR}/
sudo chmod -R 775 ${MEDIA_DIR}/
sudo chmod -R 775 ${CONFIG_DIR}/
sudo chown -R $UID:mediacenter ${DOWNLOADS_DIR}/
sudo chown -R $UID:mediacenter ${MEDIA_DIR}/
sudo chown -R $UID:mediacenter ${CONFIG_DIR}/
sudo chown -R sonarr:mediacenter ${CONFIG_DIR}/sonarr-config
sudo chown -R radarr:mediacenter ${CONFIG_DIR}/radarr-config
sudo chown -R lidarr:mediacenter ${CONFIG_DIR}/lidarr-config
sudo chown -R mylar:mediacenter ${CONFIG_DIR}/mylar-config
sudo chown -R prowlarr:mediacenter ${CONFIG_DIR}/prowlarr-config
sudo chown -R qbittorrent:mediacenter ${CONFIG_DIR}/qbittorrent-config
sudo chown -R jackett:mediacenter ${CONFIG_DIR}/jackett-config
sudo chown -R overseerr:mediacenter ${CONFIG_DIR}/overseerr-config
sudo chown -R plex:mediacenter ${CONFIG_DIR}/plex-config
sudo chown -R $UID:mediacenter ${CONFIG_DIR}/jellyfin-config
sudo chown -R $UID:mediacenter ${CONFIG_DIR}/tautulli-config
sudo chown -R sabnzbd:mediacenter ${CONFIG_DIR}/sabnzbd-config
sudo chown -R jellyseerr:mediacenter ${CONFIG_DIR}/jellyseerr-config
sudo chown -R bazarr:mediacenter ${CONFIG_DIR}/bazarr-config
sudo chown -R audiobookshelf:mediacenter ${CONFIG_DIR}/audiobookshelf-config
echo "Done! It is recommended to reboot now."