PortValhalla/scripts/Common/Software/docker/services/jellyfin/main.fish

135 lines
4.5 KiB
Fish
Executable file

#!/bin/env fish
begin
set -l dir (status dirname)
set -l user jellyfin
set -l domain media
set -l server "$domain" ""
set -l servarr radarr sonarr lidarr prowlarr
set -l flood flood
set -l service $user
source "$dir/../service.fish"
function installSW -V dir -V domain -V server -V service
set -l root (getServiceRoot $argv)
set -l overrides (getServiceOverrides $argv)
set -l source "$dir/$(basename "$overrides")"
set -l port (getRandomPort)
set -l servarrKeys
initializeServiceInstallation $argv
sudo cp "$dir/docker-compose.base.yml" "$root"
sudo cp "$dir/.dockerignore" "$root"
sudo cp "$dir/pvpn-cli.py" "$root"
sudo cp "$dir/rtorrent.Dockerfile" "$root"
sudo cp "$source" "$overrides"
installDockerService $argv
end
function configureSW -V dir -V user -V domain -V service -V servarr -V flood
set -l uid
set -l gid
set -l port
set -l file (mktemp)
set -l root (getServiceRoot $argv)
set -l config "$root/docker-compose.base.yml"
set -l overrides (getServiceOverrides $argv)
set -l envKey "$(getServiceKey "$service").environment"
configureDockerService $argv
and sudo useradd \
--system \
--shell /bin/false \
--comment 'Jellyfin server' \
--create-home \
$user
set uid (id -u $user)
set gid (id -g $user)
for name in $service $flood
set -l userKey "$(getServiceKey "$name").user"
cp "$config" "$file"
USER=$uid:$gid yq "$userKey = env(USER)" "$file" | sudo tee "$config" >/dev/null
end
for name in $servarr rtorrent
set -l envKey "$(getServiceKey "$name").environment"
sudo cp "$config" "$file"
and yq "$envKey.PUID = $uid" "$file" |
yq "$envKey.PGID = $gid" |
sudo tee "$config" >/dev/null
end
cp "$overrides" "$file"
URL="https://$(getServiceDomain "$domain" "")/" yq "$(getServiceKey "$service").environment.JELLYFIN_PublishedServerUrl = env(URL)" "$file" |
sudo tee "$overrides" >/dev/null
for dir in "$root"/data/{downloads,config/{,jellyfin,flood,radarr,sonarr,lidarr,prowlarr},media/{,movies,series,music}}
sudo mkdir -p "$dir"
and sudo chown -R $uid:$gid "$dir"
end
rm "$file"
end
function getServiceServers -V server
printf "%s\0" $server
end
function getServiceLocations -V servarr -V flood
argparse -i "name=" -- $argv
printf "%s\0" \
"$_flag_name" / "" (
for app in $servarr
printf "%s\n" "$app" "/$app" ""
end) \
flood "/flood/"
end
function getServiceLocationConfig -a domain s location -V service -V flood
if [ "$s" = "$service" ]
set -l argv $argv[4..]
printf "%s\n" \
"location = / {" \
'return 302 $scheme://$host/web/;' \
"}"
getServiceDefaultProxy $domain $s "$location" --comment "Proxy main Jellyfin traffic" $argv
getServiceDefaultProxy $domain $s "= /web/" --path "/web/index.html" --comment "Proxy main Jellyfin traffic" $argv
getServiceDefaultProxy $domain $s /socket --comment "Proxy Jellyfin Websockets traffic" $argv
else if [ "$s" = "$flood" ]
getServiceDefaultProxy $argv
printf "%s\n" \
"location = /flood {" \
'return 302 $scheme://$host$uri/$is_args$args;' \
"}"
else
getServiceDefaultProxy $argv --path "$location"
end
end
function getExtraLocationSettings -a domain s location -V service
if [ "$s" = "$service" ]
if [ "$location" = / ]
printf "%s\n" \
"# Disable buffering when the nginx proxy gets very resource heavy upon streaming" \
"proxy_buffering off;"
else if [ "$location" = /socket ]
printf "%s\n" \
'# Websocket' \
"proxy_http_version 1.1;" \
'proxy_set_header Upgrade $http_upgrade;' \
'proxy_set_header Connection "upgrade";'
end
end
end
function getExtraBackupPatterns
echo "^proton\.env\$"
end
runInstaller --force $argv
end