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

144 lines
4.7 KiB
Fish
Raw Normal View History

2024-11-10 11:33:36 +00:00
#!/bin/env fish
begin
set -l dir (status dirname)
2024-11-29 00:13:58 +00:00
set -l user jellyfin
set -l domain media
2024-11-10 11:33:36 +00:00
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)
2024-11-27 01:54:44 +00:00
set -l overrides (getServiceOverrides $argv)
set -l source "$dir/$(basename "$overrides")"
2024-11-10 11:33:36 +00:00
set -l port (getRandomPort)
set -l servarrKeys
initializeServiceInstallation $argv
2024-11-13 15:22:57 +00:00
sudo cp "$dir/docker-compose.base.yml" "$root"
2024-11-10 11:33:36 +00:00
sudo cp "$dir/.dockerignore" "$root"
sudo cp "$dir/pvpn-cli.py" "$root"
sudo cp "$dir/rtorrent.Dockerfile" "$root"
2024-11-27 01:54:44 +00:00
sudo cp "$source" "$overrides"
2024-11-10 11:33:36 +00:00
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)
2024-11-13 15:22:57 +00:00
set -l config "$root/docker-compose.base.yml"
2024-11-27 01:54:44 +00:00
set -l overrides (getServiceOverrides $argv)
2024-11-10 11:33:36 +00:00
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"
2024-11-19 23:30:08 +00:00
USER=$uid:$gid yq "$userKey = env(USER)" "$file" | sudo tee "$config" >/dev/null
2024-11-10 11:33:36 +00:00
end
for name in $servarr rtorrent
set -l envKey "$(getServiceKey "$name").environment"
sudo cp "$config" "$file"
2024-11-29 00:13:58 +00:00
and yq "$envKey.PUID = $uid" "$file" |
yq "$envKey.PGID = $gid" |
2024-11-10 11:33:36 +00:00
sudo tee "$config" >/dev/null
end
2024-11-27 01:54:44 +00:00
cp "$overrides" "$file"
2024-11-29 00:13:58 +00:00
URL="https://$(getServiceDomain "$domain" "")/" yq "$(getServiceKey "$service").environment.JELLYFIN_PublishedServerUrl = env(URL)" "$file" |
2024-11-27 01:54:44 +00:00
sudo tee "$overrides" >/dev/null
2024-11-10 11:33:36 +00:00
for dir in "$root"/data/{downloads,config/{,jellyfin,flood,radarr,sonarr,lidarr,prowlarr},media/{,movies,series,music}}
2024-11-10 11:33:36 +00:00
sudo mkdir -p "$dir"
2024-12-06 12:51:08 +00:00
and sudo chown -R $uid:$gid "$dir"
2024-11-10 11:33:36 +00:00
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" \
2024-12-06 12:50:58 +00:00
"$_flag_name" / "" (
2024-11-10 11:33:36 +00:00
for app in $servarr
printf "%s\n" "$app" "/$app" ""
2024-12-11 01:27:49 +00:00
printf "%s\n" "$app" "/$app/signalr" ""
2024-11-10 11:33:36 +00:00
end) \
2024-12-04 15:57:58 +00:00
flood "/flood/"
2024-11-10 11:33:36 +00:00
end
function getServiceLocationConfig -a domain s location -V service -V flood
if [ "$s" = "$service" ]
set -l argv $argv[4..]
2024-11-29 00:13:58 +00:00
2024-11-10 11:33:36 +00:00
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
2024-11-29 00:13:58 +00:00
getServiceDefaultProxy $domain $s /socket --comment "Proxy Jellyfin Websockets traffic" $argv
2024-11-10 11:33:36 +00:00
else if [ "$s" = "$flood" ]
getServiceDefaultProxy $argv
printf "%s\n" \
"location = /flood {" \
2024-12-04 16:02:11 +00:00
'return 302 $scheme://$host$uri/$is_args$args;' \
2024-11-10 11:33:36 +00:00
"}"
else
2024-12-11 01:27:49 +00:00
getServiceDefaultProxy $argv
2024-11-10 11:33:36 +00:00
end
end
2024-12-11 01:27:49 +00:00
function getExtraLocationSettings -a domain s location -V service -V servarr
set -l wsConfig (
printf "%s\n" \
'# Websocket' \
"proxy_http_version 1.1;" \
'proxy_set_header Upgrade $http_upgrade;' \
'proxy_set_header Connection "upgrade";')
2024-11-10 11:33:36 +00:00
if [ "$s" = "$service" ]
if [ "$location" = / ]
printf "%s\n" \
"# Disable buffering when the nginx proxy gets very resource heavy upon streaming" \
"proxy_buffering off;"
2024-11-29 00:13:58 +00:00
else if [ "$location" = /socket ]
2024-12-11 01:27:49 +00:00
echo "$wsConfig"
end
else if contains "$s" $servarr
if string match --regex ".*/signalr^" "$location" >/dev/null
echo "$wsConfig"
2024-11-10 11:33:36 +00:00
end
end
end
function getExtraBackupPatterns
echo "^proton\.env\$"
2024-11-10 11:33:36 +00:00
end
runInstaller --force $argv
end