Allow splitting config, downloads and media paths via .env
Some checks failed
Check running / run (push) Has been cancelled

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.
This commit is contained in:
2026-04-17 10:40:44 +02:00
parent d9a03a5d25
commit 92aa9b4c22
7 changed files with 292 additions and 112 deletions

View File

@@ -9,8 +9,23 @@ TIMEZONE=Europe/Amsterdam
PLEX_CLAIM=
# Choose your root directory for keeping all your container configs and data.
# This is used as the default base path when the more specific *_DIR variables below are left empty.
ROOT_DIR=
# Optional: override individual locations independently of ROOT_DIR. Leave empty to derive them from ROOT_DIR.
# Defaults:
# CONFIG_DIR = ${ROOT_DIR}/config (per-service config folders)
# DOWNLOADS_DIR = ${ROOT_DIR}/data (contains torrents/ and usenet/)
# MEDIA_DIR = ${ROOT_DIR}/data/media (final media library: tv, movies, music, ...)
#
# IMPORTANT: the TRaSH guide relies on hardlinks and atomic moves between downloads and media.
# Hardlinks only work when DOWNLOADS_DIR and MEDIA_DIR are on the SAME filesystem. If you put them
# on different drives/mounts, Sonarr/Radarr/etc. will fall back to copying, using extra disk space
# and time. Split these only if you understand that trade-off.
CONFIG_DIR=
DOWNLOADS_DIR=
MEDIA_DIR=
# USER IDs for each container that requires their own user. The default values will most likely suffice, but in case one of these IDs is already in use on your system it will have to be changed. Any value should work as long as there aren't conflicts with other users.
# If you've already set up the containers and want to change user IDs after the fact, you have to remove the old users first and re-set permissions. First run remove_old_users.sh and then the steps for manual installation.
# If you're doing a manual installation make sure to first change the IDs in this file, and then run setup.sh to set up the directory structure and permissions before you start the docker containers.

101
README.md
View File

@@ -55,9 +55,13 @@ For other Linux distros you may have to use a different package manager or downl
### Using the CLI
To make things easier, a CLI has been developed. First, clone the repository in a directory of your
choosing. You can run it by entering `python3 main.py` and the CLI will guide you through the
process. This is the recommended method if you're setting this up for the first time on a new system.
Please take a look at [important notes](#important-notes) before you continue.
**NOTE: This script will create users for each container with IDs ranging from 13001 to 13014.
process. It will ask which services to enable, your timezone, your root directory, and — if you
want — independent absolute paths for your configs, downloads and media trees (press enter at each
prompt to keep the `ROOT_DIR`-based default). See [Storage layouts](#storage-layouts) below for the
trade-offs when splitting those.
This is the recommended method if you're setting this up for the first time on a new system.
Please take a look at [important notes](#important-notes) before you continue.
**NOTE: This script will create users for each container with IDs ranging from 13001 to 13014.
If you want to choose your own IDs (or some of them are occupied) you have to go through the manual install.**
### Manually
@@ -65,9 +69,55 @@ If you're installing this for the first time simply follow these steps.
If you're coming from an older version or reinstalling with different IDs, run `remove_old_users.sh` to clean up old users and then follow these steps.
1. To get started, clone the repository in a directory of your choosing. `git clone https://github.com/Luctia/ezarr.git`
2. Copy `.env.sample` to a real `.env` by running `$ cp .env.sample .env`.
3. Set the environment variables to your liking. Pay special attention `ROOT_DIR` as this is where everything is going to be stored in.
3. Set the environment variables to your liking. Pay special attention `ROOT_DIR` as this is where everything is going to be stored in.
The path in this value needs to be **absolute**. If you leave it empty it's going to install in the directory the .env file is currently in.
`UID` should be set to the ID of the user that you want to run docker with. You can find this by running `id -u` from that user's shell.
If you want to spread configs, downloads and media across different locations (e.g. SSD for configs, bulk HDD for media), set `CONFIG_DIR`, `DOWNLOADS_DIR` and/or `MEDIA_DIR` to absolute paths. Any of them left empty fall back to `${ROOT_DIR}/config`, `${ROOT_DIR}/data` and `${ROOT_DIR}/data/media` respectively. **Note:** hardlinks/atomic moves between downloads and media only work when `DOWNLOADS_DIR` and `MEDIA_DIR` live on the same filesystem — split them only if you understand that you'll be copying instead of hardlinking.
The generated folder structure on the host looks like this (the three top-level trees can live under one `ROOT_DIR` or be spread across different drives via the `*_DIR` overrides):
```
${CONFIG_DIR}/ # default: ${ROOT_DIR}/config
├── sonarr-config/
├── radarr-config/
├── lidarr-config/
├── mylar-config/
├── prowlarr-config/
├── jackett-config/
├── qbittorrent-config/
├── sabnzbd-config/
├── bazarr-config/
├── overseerr-config/
├── jellyseerr-config/
├── plex-config/
├── jellyfin-config/
├── tautulli-config/
└── audiobookshelf-config/
${DOWNLOADS_DIR}/ # default: ${ROOT_DIR}/data
├── torrents/ # qBittorrent save path
│ ├── tv/
│ ├── movies/
│ ├── music/
│ ├── comics/
│ └── ...
└── usenet/ # SABnzbd complete/incomplete
├── tv/
├── movies/
├── music/
├── comics/
└── ...
${MEDIA_DIR}/ # default: ${ROOT_DIR}/data/media
├── tv/ # Sonarr
├── movies/ # Radarr
├── music/ # Lidarr
├── comics/ # Mylar3
├── books/
├── audiobooks/ # Audiobookshelf
├── podcasts/ # Audiobookshelf
└── audiobookshelf-metadata/
```
Inside the -arr containers these are always exposed under a single `/data` tree — `/data/torrents`, `/data/usenet`, `/data/media/{tv,movies,...}` — regardless of how the host paths are split. This preserves the TRaSH single-`/data`-mount pattern and keeps hardlinks working as long as `DOWNLOADS_DIR` and `MEDIA_DIR` share a filesystem. The compose file achieves this by binding `${DOWNLOADS_DIR}:/data` as the parent and overlaying `${MEDIA_DIR}:/data/media` on top.
4. Run `setup.sh` as superuser. This will set up your users, a system of directories and ensure permissions are set correctly.
5. Copy `docker-compose.yml.sample` to a real `docker-compose.yml` by running `$ cp docker-compose.yml.sample docker-compose.yml`.
6. Take a look at the `docker-compose.yml` file. If there are services you would like to ignore
@@ -86,6 +136,41 @@ If you're coming from an older version or reinstalling with different IDs, run `
That's it! Your containers are now up and you can continue to set up the settings in them. Please
take a look at [important notes](#important-notes) before you continue.
## Storage layouts
The -arr services use **hardlinks** to move downloaded files from `torrents/` or `usenet/` into the
media library without duplicating bytes. Hardlinks only work within a single filesystem — so
`DOWNLOADS_DIR` and `MEDIA_DIR` must resolve to paths on the same filesystem for this to work. If
they don't, Sonarr/Radarr/Lidarr/Mylar will silently fall back to copying, which uses twice the
disk space and a lot more I/O on every import. `CONFIG_DIR` has no such constraint and can live
anywhere.
Some layouts that work well:
- **Single-drive / single-filesystem (simplest).** Set `ROOT_DIR` and leave `CONFIG_DIR`,
`DOWNLOADS_DIR`, `MEDIA_DIR` empty. Everything lives under one tree, hardlinks just work.
- **SSD for configs, HDD for everything else.** Set `CONFIG_DIR=/ssd/ezarr/config` and leave the
other two empty (they default under `ROOT_DIR`, which you point at the HDD). Config databases
benefit from the faster disk; downloads + media stay together so hardlinks work.
- **Pooled storage with [mergerfs](https://github.com/trapexit/mergerfs).** Combine multiple
HDDs into one mount point (e.g. `/pool`) and point `ROOT_DIR` or `DOWNLOADS_DIR`+`MEDIA_DIR` at
it. With `category.create=epmfs` and `moveonenospc=true`, mergerfs keeps a torrent and its
hardlinked media file on the same underlying disk, so `link(2)` succeeds inside the pool.
- **CoW filesystems (btrfs / xfs with reflink / bcachefs / ZFS).** Same-filesystem rule still
applies, but you also get reflinks (instant, space-sharing copies) as a fallback when hardlinks
aren't appropriate.
Layouts that will **break hardlinks** (they will still run, just less efficiently):
- `DOWNLOADS_DIR` on one drive/mount and `MEDIA_DIR` on a different drive/mount.
- Downloads on local disk, media on a remote NFS/SMB share (or vice versa).
- Either path going through a union filesystem that doesn't co-locate related files.
If you genuinely need split storage and can't pool it, set "Use Hardlinks" to `false` in each -arr
and accept the copy overhead.
Regardless of how you split the host paths, the compose file always exposes a single `/data` tree
inside the -arr containers — `/data/torrents`, `/data/usenet`, `/data/media/{tv,movies,...}` — so
the root-folder paths you configure in Sonarr/Radarr/etc. never need to change.
## Important notes
- You probably shouldn't run the python script as root. Ideally you should create a brand new user that's just for these services, but any regular user will do.
It will need your password for `sudo` to set up the permissions and folder structures, but you shouldn't run it *as* root.
@@ -114,11 +199,13 @@ Note that if you are a group member (and not the owner), having matching group I
the users and groups are set up on both sides correctly is to run `setup.sh` on both your NFS server and your client.
On your server:
- Copy `.env` and `setup.sh` to your NFS server.
- You may have to adjust `.env` so that `ROOT_DIR` reflects where it will be stored on your server, which is most likely different from the mapped location on the client.
- You may have to adjust `.env` so that `ROOT_DIR` (and `CONFIG_DIR` / `DOWNLOADS_DIR` / `MEDIA_DIR`, if you've set any of them) reflect where each tree will be stored on your server, which is most likely different from the mapped location on the client.
- Make sure that the `.env` file is not a .sample. Run `setup.sh`.
- Now follow all the same steps but on your client machine. Always double-check that `.env` is set correctly, especially `ROOT_DIR`.
You don't have to do this on your server first but it's recommended. If you are running this script on the client **make sure that you temporarily enable -no-root-squash on your NFS server**,
- Now follow all the same steps but on your client machine. Always double-check that `.env` is set correctly, especially the path variables above.
You don't have to do this on your server first but it's recommended. If you are running this script on the client **make sure that you temporarily enable -no-root-squash on your NFS server**,
as the script needs superuser privileges to run and by default on NFS the root user is mapped to nowhere to prevent abuse.
**Heads-up on hardlinks over NFS:** if your downloads live on the local disk but media lives on an NFS mount (or vice versa), that's two different filesystems and hardlinks will break — see [Storage layouts](#storage-layouts) for the options. Keeping `DOWNLOADS_DIR` and `MEDIA_DIR` both on the NFS mount is fine, as long as they share the same share/filesystem.
### SABnzbd External internet access denied message
When you're trying to access SABnzbd the first time you'll come across the message `External

View File

@@ -7,21 +7,42 @@ class ContainerConfig:
root_dir,
timezone,
plex_claim='',
config_dir=None,
downloads_dir=None,
media_dir=None,
):
self.root_dir = root_dir
self.timezone = timezone
self.config_dir = f'{root_dir}/config'
self.plex_claim = plex_claim
self.movie_dir = f'{root_dir}/media/movies'
self.tv_dir = f'{root_dir}/media/tv'
self.music_dir = f'{root_dir}/media/music'
self.book_dir = f'{root_dir}/media/books'
self.comic_dir = f'{root_dir}/media/comics'
self.torrent_dir = f'{root_dir}/data/torrents'
self.usenet_dir = f'{root_dir}/data/usenet'
# Allow each of config / downloads / media to be overridden independently.
# When not provided, fall back to the ROOT_DIR-based defaults used historically.
self.config_dir = config_dir or f'{root_dir}/config'
self.downloads_dir = downloads_dir or f'{root_dir}/data'
self.media_dir = media_dir or f'{root_dir}/data/media'
self.movie_dir = f'{self.media_dir}/movies'
self.tv_dir = f'{self.media_dir}/tv'
self.music_dir = f'{self.media_dir}/music'
self.book_dir = f'{self.media_dir}/books'
self.comic_dir = f'{self.media_dir}/comics'
self.torrent_dir = f'{self.downloads_dir}/torrents'
self.usenet_dir = f'{self.downloads_dir}/usenet'
self.homarr_dir = f'{root_dir}/data/homarr/appdata'
self.UID = pwd.getpwnam(getpass.getuser()).pw_uid
def _arr_data_volumes(self):
"""Volume lines for services that need the full /data tree (sonarr, radarr, lidarr, mylar3).
Emits a single ``${downloads_dir}:/data`` parent mount plus a ``${media_dir}:/data/media``
overlay. The overlay is a no-op when ``media_dir`` is the default ``${downloads_dir}/media``
(Docker just binds the same subpath) and transparently redirects ``/data/media`` when the
user has pointed ``media_dir`` at a different location. This preserves TRaSH's single-
``/data``-mount semantics while still allowing an independent ``MEDIA_DIR``.
"""
return (
f' - {self.downloads_dir}:/data\n'
f' - {self.media_dir}:/data/media\n'
)
def plex(self):
return (
' plex:\n'
@@ -35,7 +56,7 @@ class ContainerConfig:
f' - PLEX_CLAIM={self.plex_claim}\n'
' volumes:\n'
f' - {self.config_dir}/plex-config:/config\n'
f' - {self.root_dir}/data/media:/media\n'
f' - {self.media_dir}:/media\n'
' restart: unless-stopped\n\n'
)
@@ -69,7 +90,7 @@ class ContainerConfig:
f' - TZ={self.timezone}\n'
' volumes:\n'
f' - {self.config_dir}/jellyfin-config:/config\n'
f' - {self.root_dir}/data/media:/data\n'
f' - {self.media_dir}:/data\n'
' ports:\n'
' - "8096:8096"\n'
' restart: unless-stopped\n\n'
@@ -87,7 +108,7 @@ class ContainerConfig:
f' - TZ={self.timezone}\n'
' volumes:\n'
f' - {self.config_dir}/sonarr-config:/config\n'
f' - {self.root_dir}/data:/data\n'
f'{self._arr_data_volumes()}'
' ports:\n'
' - "8989:8989"\n'
' restart: unless-stopped\n\n'
@@ -105,7 +126,7 @@ class ContainerConfig:
f' - TZ={self.timezone}\n'
' volumes:\n'
f' - {self.config_dir}/radarr-config:/config\n'
f' - {self.root_dir}/data:/data\n'
f'{self._arr_data_volumes()}'
' ports:\n'
' - "7878:7878"\n'
' restart: unless-stopped\n\n'
@@ -122,7 +143,7 @@ class ContainerConfig:
f' - TZ={self.timezone}\n'
' volumes:\n'
f' - {self.config_dir}/bazarr-config:/config\n'
f' - {self.root_dir}/data/media:/media\n'
f' - {self.media_dir}:/media\n'
' ports:\n'
' - "6767:6767"\n'
' restart: unless-stopped\n\n'
@@ -140,7 +161,7 @@ class ContainerConfig:
f' - TZ={self.timezone}\n'
' volumes:\n'
f' - {self.config_dir}/lidarr-config:/config\n'
f' - {self.root_dir}/data:/data\n'
f'{self._arr_data_volumes()}'
' ports:\n'
' - "8686:8686"\n'
' restart: unless-stopped\n\n'
@@ -157,7 +178,7 @@ class ContainerConfig:
' - UMASK=002\n'
' volumes:\n'
f' - {self.config_dir}/mylar-config:/config\n'
f' - {self.root_dir}/data:/data\n'
f'{self._arr_data_volumes()}'
' ports:\n'
' - "8090:8090"\n'
' restart: unless-stopped\n\n'
@@ -173,9 +194,9 @@ class ContainerConfig:
f' - TZ={self.timezone}\n'
' volumes:\n'
f' - {self.config_dir}/audiobookshelf:/config\n'
f' - {self.root_dir}/data/media/audiobooks:/audiobooks\n'
f' - {self.root_dir}/data/media/podcasts:/podcasts\n'
f' - {self.root_dir}/data/media/audiobookshelf-metadata:/metadata\n'
f' - {self.media_dir}/audiobooks:/audiobooks\n'
f' - {self.media_dir}/podcasts:/podcasts\n'
f' - {self.media_dir}/audiobookshelf-metadata:/metadata\n'
' ports:\n'
' - "13378:80"\n'
' restart: unless-stopped\n\n'

View File

@@ -10,8 +10,12 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/sonarr-config:/config
- ${ROOT_DIR}/data:/data
- ${CONFIG_DIR:-${ROOT_DIR}/config}/sonarr-config:/config
# Single /data parent mount (TRaSH-style) + MEDIA_DIR overlay at /data/media.
# When MEDIA_DIR is left at its default, the overlay is redundant but harmless;
# when overridden, it transparently redirects /data/media to the new location.
- ${DOWNLOADS_DIR:-${ROOT_DIR}/data}:/data
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/data/media
ports:
- "8989:8989"
restart: unless-stopped
@@ -25,8 +29,9 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/radarr-config:/config
- ${ROOT_DIR}/data:/data
- ${CONFIG_DIR:-${ROOT_DIR}/config}/radarr-config:/config
- ${DOWNLOADS_DIR:-${ROOT_DIR}/data}:/data
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/data/media
ports:
- "7878:7878"
restart: unless-stopped
@@ -40,8 +45,9 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/lidarr-config:/config
- ${ROOT_DIR}/data:/data
- ${CONFIG_DIR:-${ROOT_DIR}/config}/lidarr-config:/config
- ${DOWNLOADS_DIR:-${ROOT_DIR}/data}:/data
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/data/media
ports:
- "8686:8686"
restart: unless-stopped
@@ -54,8 +60,9 @@ services:
- PGID=${MEDIACENTER_GID}
- UMASK=002
volumes:
- ${ROOT_DIR}/config/mylar-config:/config
- ${ROOT_DIR}/data:/data
- ${CONFIG_DIR:-${ROOT_DIR}/config}/mylar-config:/config
- ${DOWNLOADS_DIR:-${ROOT_DIR}/data}:/data
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/data/media
ports:
- "8090:8090"
restart: unless-stopped
@@ -67,10 +74,10 @@ services:
- user=${AUDIOBOOKSHELF_UID}:${MEDIACENTER_GID}
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/audiobookshelf:/config
- ${ROOT_DIR}/data/media/audiobooks:/audiobooks
- ${ROOT_DIR}/data/media/podcasts:/podcasts
- ${ROOT_DIR}/data/media/audiobookshelf-metadata:/metadata
- ${CONFIG_DIR:-${ROOT_DIR}/config}/audiobookshelf:/config
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}/audiobooks:/audiobooks
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}/podcasts:/podcasts
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}/audiobookshelf-metadata:/metadata
ports:
- "13378:80"
restart: unless-stopped
@@ -83,8 +90,8 @@ services:
- PGID=${MEDIACENTER_GID}
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/bazarr-config:/config
- ${ROOT_DIR}/data/media:/media
- ${CONFIG_DIR:-${ROOT_DIR}/config}/bazarr-config:/config
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/media
ports:
- "6767:6767"
restart: unless-stopped
@@ -98,7 +105,7 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/overseerr-config:/app/config
- ${CONFIG_DIR:-${ROOT_DIR}/config}/overseerr-config:/app/config
ports:
- "5055:5055"
restart: unless-stopped
@@ -112,7 +119,7 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/jellyseerr-config:/app/config
- ${CONFIG_DIR:-${ROOT_DIR}/config}/jellyseerr-config:/app/config
ports:
- "5056:5055"
restart: unless-stopped
@@ -126,7 +133,7 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/prowlarr-config:/config
- ${CONFIG_DIR:-${ROOT_DIR}/config}/prowlarr-config:/config
ports:
- "9696:9696"
restart: unless-stopped
@@ -142,7 +149,7 @@ services:
- SECRET_ENCRYPTION_KEY=
ports:
- "7575:7575"
jackett:
image: lscr.io/linuxserver/jackett:latest
container_name: jackett
@@ -150,9 +157,9 @@ services:
- PUID=${JACKETT_UID}
- PGID=${MEDIACENTER_GID}
- UMASK=002
- TZ=${TIMEZONE}
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/jackett-config:/config
- ${CONFIG_DIR:-${ROOT_DIR}/config}/jackett-config:/config
ports:
- 9117:9117
restart: unless-stopped
@@ -179,22 +186,22 @@ services:
- VERSION=docker
- PLEX_CLAIM=${PLEX_CLAIM}
volumes:
- ${ROOT_DIR}/config/plex-config:/config
- ${ROOT_DIR}/data/media:/media
- ${CONFIG_DIR:-${ROOT_DIR}/config}/plex-config:/config
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/media
restart: unless-stopped
tautulli:
image: lscr.io/linuxserver/tautulli:latest
container_name: tautulli
# commented out because plex can also run outside of docker
#depends_on:
#depends_on:
# - plex
environment:
- PUID=${UID}
- PGID=${MEDIACENTER_GID}
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/tautulli-config:/config
- ${CONFIG_DIR:-${ROOT_DIR}/config}/tautulli-config:/config
ports:
- "8181:8181"
restart: unless-stopped
@@ -208,8 +215,8 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/jellyfin-config:/config
- ${ROOT_DIR}/data/media:/data
- ${CONFIG_DIR:-${ROOT_DIR}/config}/jellyfin-config:/config
- ${MEDIA_DIR:-${ROOT_DIR}/data/media}:/data
ports:
- "8096:8096"
restart: unless-stopped
@@ -224,8 +231,8 @@ services:
- TZ=${TIMEZONE}
- WEBUI_PORT=8080
volumes:
- ${ROOT_DIR}/config/qbittorrent-config:/config
- ${ROOT_DIR}/data/torrents:/data/torrents
- ${CONFIG_DIR:-${ROOT_DIR}/config}/qbittorrent-config:/config
- ${DOWNLOADS_DIR:-${ROOT_DIR}/data}/torrents:/data/torrents
ports:
- "8080:8080"
- "6881:6881"
@@ -241,8 +248,8 @@ services:
- UMASK=002
- TZ=${TIMEZONE}
volumes:
- ${ROOT_DIR}/config/sabnzbd-config:/config
- ${ROOT_DIR}/data/usenet:/data/usenet
- ${CONFIG_DIR:-${ROOT_DIR}/config}/sabnzbd-config:/config
- ${DOWNLOADS_DIR:-${ROOT_DIR}/data}/usenet:/data/usenet
ports:
- "8081:8080"
restart: unless-stopped

41
main.py
View File

@@ -33,6 +33,16 @@ def take_directory_input():
return ans
print('Please make sure the path is absolute, meaning it starts at the root of your filesystem and starts with "/":', end=' ')
def take_optional_directory_input(default):
"""Reads a directory override, or returns ``default`` on an empty response."""
while True:
ans = input()
if ans == '':
return default
if ans[0] == '/':
return ans[:-1] if ans[-1] == '/' else ans
print(f'Please provide an absolute path (starting with "/") or press enter to use "{default}":', end=' ')
def get_system_timezone():
tz_path = '/etc/localtime'
@@ -121,13 +131,35 @@ def main():
print('Where would you like to keep your files?', end=' ')
root_dir = take_directory_input()
default_config_dir = f'{root_dir}/config'
default_downloads_dir = f'{root_dir}/data'
default_media_dir = f'{root_dir}/data/media'
print('\nBy default all configs, downloads and media go under the root directory you just picked.')
print('You can override any of these three with an absolute path, or press enter to accept the default.')
print('NOTE: hardlinks/atomic moves only work when downloads and media are on the same filesystem.')
print(f'Config directory [{default_config_dir}]:', end=' ')
config_dir = take_optional_directory_input(default_config_dir)
print(f'Downloads directory [{default_downloads_dir}]:', end=' ')
downloads_dir = take_optional_directory_input(default_downloads_dir)
print(f'Media directory [{default_media_dir}]:', end=' ')
media_dir = take_optional_directory_input(default_media_dir)
compose = open('docker-compose.yml', 'w')
compose.write(
'---\n'
'services:\n'
)
container_config = ContainerConfig(root_dir, timezone, plex_claim=plex_claim)
container_config = ContainerConfig(
root_dir,
timezone,
plex_claim=plex_claim,
config_dir=config_dir,
downloads_dir=downloads_dir,
media_dir=media_dir,
)
for service in services:
compose.write(getattr(container_config, service)())
@@ -137,7 +169,12 @@ def main():
print("Do you want to also generate the required folder structure and permissions? (this is required for first time setup) [Y/n]: ")
generate_permissions = take_boolean_input()
if generate_permissions:
permission_setup = UserGroupSetup(root_dir=root_dir)
permission_setup = UserGroupSetup(
root_dir=root_dir,
config_dir=config_dir,
downloads_dir=downloads_dir,
media_dir=media_dir,
)
for service in services:
try:
getattr(permission_setup, service)()

View File

@@ -5,10 +5,21 @@
set -a
source .env
set +a
# This is always going to complain about UID being a read-only variable.
# 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
@@ -28,10 +39,10 @@ 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.
# 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
# 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
@@ -47,29 +58,31 @@ sudo usermod -a -G mediacenter bazarr
sudo usermod -a -G mediacenter audiobookshelf
# Make directories
# ${ROOT_DIR:-.}/ means take the value from ROOT_DIR value, if failed or empty place it in the current folder
sudo mkdir -pv ${ROOT_DIR:-.}/config/{sonarr,radarr,lidarr,mylar,prowlarr,qbittorrent,jackett,audiobookshelf,overseerr,plex,jellyfin,tautulli,sabnzbd,jellyseerr,bazarr}-config
sudo mkdir -pv ${ROOT_DIR:-.}/data/{torrents,usenet,media}/{tv,movies,music,books,comics,audiobooks,podcasts,audiobookshelf-metadata}
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 ${ROOT_DIR:-.}/data/
sudo chmod -R 775 ${ROOT_DIR:-.}/config/
sudo chown -R $UID:mediacenter ${ROOT_DIR:-.}/data/
sudo chown -R $UID:mediacenter ${ROOT_DIR:-.}/config/
sudo chown -R sonarr:mediacenter ${ROOT_DIR:-.}/config/sonarr-config
sudo chown -R radarr:mediacenter ${ROOT_DIR:-.}/config/radarr-config
sudo chown -R lidarr:mediacenter ${ROOT_DIR:-.}/config/lidarr-config
sudo chown -R mylar:mediacenter ${ROOT_DIR:-.}/config/mylar-config
sudo chown -R prowlarr:mediacenter ${ROOT_DIR:-.}/config/prowlarr-config
sudo chown -R qbittorrent:mediacenter ${ROOT_DIR:-.}/config/qbittorrent-config
sudo chown -R jackett:mediacenter ${ROOT_DIR:-.}/config/jackett-config
sudo chown -R overseerr:mediacenter ${ROOT_DIR:-.}/config/overseerr-config
sudo chown -R plex:mediacenter ${ROOT_DIR:-.}/config/plex-config
sudo chown -R $UID:mediacenter ${ROOT_DIR:-.}/config/jellyfin-config
sudo chown -R $UID:mediacenter ${ROOT_DIR:-.}/config/tautulli-config
sudo chown -R sabnzbd:mediacenter ${ROOT_DIR:-.}/config/sabnzbd-config
sudo chown -R jellyseerr:mediacenter ${ROOT_DIR:-.}/config/jellyseerr-config
sudo chown -R bazarr:mediacenter ${ROOT_DIR:-.}/config/bazarr-config
sudo chown -R audiobookshelf:mediacenter ${ROOT_DIR:-.}/config/audiobookshelf-config
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."

View File

@@ -2,38 +2,46 @@ import os
class UserGroupSetup:
def __init__(self, root_dir='/'):
def __init__(self, root_dir='/', config_dir=None, downloads_dir=None, media_dir=None):
self.root_dir = root_dir
# Individual location overrides with ROOT_DIR-based fallbacks.
self.config_dir = config_dir or f'{root_dir}/config'
self.downloads_dir = downloads_dir or f'{root_dir}/data'
self.media_dir = media_dir or f'{root_dir}/data/media'
os.system('sudo groupadd mediacenter -g 13000')
os.system('sudo usermod -a -G mediacenter $USER')
os.system(
'/bin/bash -c "sudo mkdir -pv ' + self.root_dir + '/data/{media,usenet,torrents} -m 775'
' ; sudo chown $(id -u):mediacenter ' + self.root_dir + '/data'
' ; sudo chown $(id -u):mediacenter ' + self.root_dir + '/data/{media,usenet,torrents}"'
f'/bin/bash -c "sudo mkdir -pv {self.downloads_dir}/{{usenet,torrents}} -m 775'
f' ; sudo mkdir -pv {self.media_dir} -m 775'
f' ; sudo chown $(id -u):mediacenter {self.downloads_dir}'
f' ; sudo chown $(id -u):mediacenter {self.downloads_dir}/{{usenet,torrents}}'
f' ; sudo chown $(id -u):mediacenter {self.media_dir}"'
)
def create_config_dir(self, service_name):
os.system(
f'sudo mkdir -p {self.root_dir}/config/{service_name}-config -m 775' # -m 775 gives read/write access to the whole mediacenter group, change to 755 for only read
f' ; sudo chown -R {service_name}:mediacenter {self.root_dir}/config/{service_name}-config'
f' ; sudo chown $(id -u):mediacenter {self.root_dir}/config'
f'sudo mkdir -p {self.config_dir}/{service_name}-config -m 775' # -m 775 gives read/write access to the whole mediacenter group, change to 755 for only read
f' ; sudo chown -R {service_name}:mediacenter {self.config_dir}/{service_name}-config'
f' ; sudo chown $(id -u):mediacenter {self.config_dir}'
)
def _make_media_subdir(self, service_name, uid, media_subdir):
"""Create matching subdirs under downloads/ and media/ and chown them to the given service user."""
os.system(
f'/bin/bash -c "sudo useradd {service_name} -u {uid}'
f' ; sudo mkdir -pv {self.downloads_dir}/{{usenet,torrents}}/{media_subdir} -m 775'
f' ; sudo mkdir -pv {self.media_dir}/{media_subdir} -m 775'
f' ; sudo chown -R {service_name}:mediacenter {self.downloads_dir}/{{usenet,torrents}}/{media_subdir}'
f' ; sudo chown -R {service_name}:mediacenter {self.media_dir}/{media_subdir}"'
)
def sonarr(self):
os.system(
'/bin/bash -c "sudo useradd sonarr -u 13001'
' ; sudo mkdir -pv ' + self.root_dir + '/data/{media,usenet,torrents}/tv -m 775'
' ; sudo chown -R sonarr:mediacenter ' + self.root_dir + '/data/{media,usenet,torrents}/tv"'
)
self._make_media_subdir('sonarr', 13001, 'tv')
self.create_config_dir('sonarr')
os.system('sudo usermod -a -G mediacenter sonarr')
def radarr(self):
os.system(
'/bin/bash -c "sudo useradd radarr -u 13002'
' ; sudo mkdir -pv ' + self.root_dir + '/data/{media,usenet,torrents}/movies -m 775'
' ; sudo chown -R radarr:mediacenter ' + self.root_dir + '/data/{media,usenet,torrents}/movies"'
)
self._make_media_subdir('radarr', 13002, 'movies')
self.create_config_dir('radarr')
os.system('sudo usermod -a -G mediacenter radarr')
@@ -43,28 +51,20 @@ class UserGroupSetup:
os.system('sudo usermod -a -G mediacenter bazarr')
def lidarr(self):
os.system(
'/bin/bash -c "sudo useradd lidarr -u 13003'
' ; sudo mkdir -pv ' + self.root_dir + '/data/{media,usenet,torrents}/music -m 775'
' ; sudo chown -R lidarr:mediacenter ' + self.root_dir + '/data/{media,usenet,torrents}/music"'
)
self._make_media_subdir('lidarr', 13003, 'music')
self.create_config_dir('lidarr')
os.system('sudo usermod -a -G mediacenter lidarr')
def mylar3(self):
os.system(
'/bin/bash -c "sudo useradd mylar -u 13005'
' ; sudo mkdir -pv ' + self.root_dir + '/data/{media,usenet,torrents}/comics -m 775'
' ; sudo chown -R mylar:mediacenter ' + self.root_dir + '/data/{media,usenet,torrents}/comics"'
)
self._make_media_subdir('mylar', 13005, 'comics')
self.create_config_dir('mylar')
os.system('sudo usermod -a -G mediacenter mylar')
def audiobookshelf(self):
os.system(
'/bin/bash -c "sudo useradd audiobookshelf -u 13014'
' ; sudo mkdir -pv ' + self.root_dir + '/data/media/{audiobooks,podcasts,audiobookshelf-metadata} -m 775'
' ; sudo chown -R audiobookshelf:mediacenter ' + self.root_dir + '/data/media/{audiobooks,podcasts,audiobookshelf-metadata}"'
f'/bin/bash -c "sudo useradd audiobookshelf -u 13014'
f' ; sudo mkdir -pv {self.media_dir}/{{audiobooks,podcasts,audiobookshelf-metadata}} -m 775'
f' ; sudo chown -R audiobookshelf:mediacenter {self.media_dir}/{{audiobooks,podcasts,audiobookshelf-metadata}}"'
)
self.create_config_dir('audiobookshelf')
os.system('sudo usermod -a -G mediacenter audiobookshelf')