175 lines
7 KiB
Fish
Executable file
175 lines
7 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 suggest "jellyseerr"
|
|
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 suggest -V servarr -V flood
|
|
argparse -i "name=" -- $argv
|
|
printf "%s\0" \
|
|
"$_flag_name" / "" \
|
|
"$suggest" "/suggest" "Jellyseerr" (
|
|
for app in $servarr
|
|
printf "%s\n" "$app" "/$app" ""
|
|
printf "%s\n" "$app" "/$app/signalr" ""
|
|
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
|
|
end
|
|
end
|
|
|
|
function getExtraLocationSettings -a domain s location -V service -V suggest -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";')
|
|
|
|
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 ]
|
|
echo "$wsConfig"
|
|
end
|
|
else if [ "$s" = "$suggest" ]
|
|
printf "%s\n" \
|
|
"" \
|
|
'set $app \'suggest\';' \
|
|
"# Remove /suggest path to pass to the app" \
|
|
'rewrite ^/suggest/?(.*)$ /$1 break;' \
|
|
"" \
|
|
"#Redirect location headers" \
|
|
'proxy_redirect ^ /$app;' \
|
|
'proxy_redirect /setup /$app/setup;' \
|
|
'proxy_redirect /login /$app/login;' \
|
|
"" \
|
|
"# Sub filters to replace hardcoded paths" \
|
|
'proxy_set_header Accept-Encoding "";' \
|
|
'sub_filter_once off;' \
|
|
'sub_filter_types *;' \
|
|
'sub_filter \'</head>\' \'<script language="javascript">(()=>{var t="$app";let e=history.pushState;history.pushState=function a(){arguments[2]&&!arguments[2].startsWith("/"+t)&&(arguments[2]="/"+t+arguments[2]);let s=e.apply(this,arguments);return window.dispatchEvent(new Event("pushstate")),s};let a=history.replaceState;history.replaceState=function e(){arguments[2]&&!arguments[2].startsWith("/"+t)&&(arguments[2]="/"+t+arguments[2]);let s=a.apply(this,arguments);return window.dispatchEvent(new Event("replacestate")),s},window.addEventListener("popstate",()=>{console.log("popstate")})})();</script></head>\';' \
|
|
'sub_filter \'href="/"\' \'href="/$app"\';' \
|
|
'sub_filter \'href="/login"\' \'href="/$app/login"\'' \
|
|
'sub_filter \'href:"/"\' \'href:"/$app"\';' \
|
|
'sub_filter \'\/_next\' \'\/$app\/_next\';' \
|
|
'sub_filter \'/_next\' \'/$app/_next\';' \
|
|
'sub_filter \'/api/v1\' \'/$app/api/v1\';' \
|
|
'sub_filter \'/login/plex/loading\' \'/$app/login/plex/loading\';' \
|
|
'sub_filter \'/images/\' \'/$app/images/\';' \
|
|
'sub_filter \'/android-\' \'/$app/android-\';' \
|
|
'sub_filter \'/apple-\' \'/$app/apple-\';' \
|
|
'sub_filter \'/favicon\' \'/$app/favicon\';' \
|
|
'sub_filter \'/logo_\' \'/$app/logo_\';' \
|
|
'sub_filter \'/site.webmanifest\' \'/$app/site.webmanifest\';'
|
|
else if contains "$s" $servarr
|
|
if string match --regex ".*/signalr^" "$location" >/dev/null
|
|
echo "$wsConfig"
|
|
end
|
|
end
|
|
end
|
|
|
|
function getExtraBackupPatterns
|
|
echo "^proton\.env\$"
|
|
end
|
|
|
|
runInstaller --force $argv
|
|
end
|