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.
105 lines
4.5 KiB
Python
105 lines
4.5 KiB
Python
import os
|
|
|
|
|
|
class UserGroupSetup:
|
|
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(
|
|
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.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):
|
|
self._make_media_subdir('sonarr', 13001, 'tv')
|
|
self.create_config_dir('sonarr')
|
|
os.system('sudo usermod -a -G mediacenter sonarr')
|
|
|
|
def radarr(self):
|
|
self._make_media_subdir('radarr', 13002, 'movies')
|
|
self.create_config_dir('radarr')
|
|
os.system('sudo usermod -a -G mediacenter radarr')
|
|
|
|
def bazarr(self):
|
|
os.system('/bin/bash -c "sudo useradd bazarr -u 13013"')
|
|
self.create_config_dir('bazarr')
|
|
os.system('sudo usermod -a -G mediacenter bazarr')
|
|
|
|
def lidarr(self):
|
|
self._make_media_subdir('lidarr', 13003, 'music')
|
|
self.create_config_dir('lidarr')
|
|
os.system('sudo usermod -a -G mediacenter lidarr')
|
|
|
|
def mylar3(self):
|
|
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(
|
|
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')
|
|
|
|
def prowlarr(self):
|
|
os.system('sudo useradd prowlarr -u 13006')
|
|
self.create_config_dir('prowlarr')
|
|
os.system('sudo usermod -a -G mediacenter prowlarr')
|
|
|
|
def qbittorrent(self):
|
|
os.system('sudo useradd qbittorrent -u 13007')
|
|
os.system('sudo usermod -a -G mediacenter qbittorrent')
|
|
|
|
def overseerr(self):
|
|
os.system('sudo useradd overseerr -u 13009')
|
|
self.create_config_dir('overseerr')
|
|
os.system('sudo usermod -a -G mediacenter overseerr')
|
|
|
|
def plex(self):
|
|
os.system('sudo useradd plex -u 13010')
|
|
self.create_config_dir('plex')
|
|
os.system('sudo usermod -a -G mediacenter plex')
|
|
|
|
def sabnzbd(self):
|
|
os.system('sudo useradd sabnzbd -u 13011')
|
|
self.create_config_dir('sabnzbd')
|
|
os.system('sudo usermod -a -G mediacenter sabnzbd')
|
|
|
|
def jellyseerr(self):
|
|
os.system('sudo useradd jellyseerr -u 13012')
|
|
self.create_config_dir('jellyseerr')
|
|
os.system('sudo usermod -a -G mediacenter jellyseerr')
|
|
|
|
def jackett(self):
|
|
os.system('sudo useradd jackett -u 13008')
|
|
self.create_config_dir('jackett')
|
|
os.system('sudo usermod -a -G mediacenter jackett')
|