Make arr scripts idempotent

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-07-15 00:20:09 +01:00
parent e2ee815d58
commit 72ea51e1d9
25 changed files with 415 additions and 488 deletions

View File

@@ -0,0 +1,140 @@
# shellcheck shell=sh
try_forever() {
until "$@" 2>&1; do
echo "Try failed: $* - retrying in 1s"
sleep 1
done
}
try() {
attempts="$1"
shift
delay=1
count=1
while [ "$count" -le "$attempts" ]; do
if "$@" 2>&1; then
return 0
fi
if [ "$count" -lt "$attempts" ]; then
echo "Attempt $count/$attempts failed, retrying in ${delay}s..."
sleep "$delay"
delay="$(( delay * 2 ))"
fi
count="$(( count + 1 ))"
done
echo "All $attempts attempts failed for: $*"
}
wait_for_api() {
try_forever curl -sf -H "X-Api-Key: $API_KEY" "$HOST$API_SUBPATH/health"
echo "API is up!"
}
call() {
method="$1"
path="$2"
data="${3:-}"
if [ -n "$data" ]; then
curl -sf \
-X "$method" \
-H "X-Api-Key: $API_KEY" \
-H "Content-Type: application/json" \
--data-raw "$data" \
"$HOST$API_SUBPATH/$path"
else
curl -sf \
-X "$method" \
-H "X-Api-Key: $API_KEY" \
"$HOST$API_SUBPATH/$path"
fi
}
get_resources() {
call GET "$1"
}
get_resource_id() {
endpoint="$1"
ident_field="$2"
name="$3"
get_resources "$endpoint" | jq -r --arg field "$ident_field" --arg name "$name" '.[] | select(.[$field] == $name) | .id // empty'
}
insert_or_skip_resource() {
endpoint="$1"
ident_field="$2"
name="$3"
json="$4"
all="$(get_resources "$endpoint")"
id="$(printf '%s' "$all" | jq -r --arg field "$ident_field" --arg name "$name" '.[] | select(.[$field]==$name) | .id')"
if [ -n "$id" ] && [ "$id" != "null" ]; then
echo "Skipping existing $endpoint '$name' (id=$id)"
else
echo "Creating $endpoint '$name'"
call POST "$endpoint?forceSave=true" "$json"
fi
}
upsert_resource() {
endpoint="$1"
ident_field="$2"
name="$3"
json="$4"
all="$(get_resources "$endpoint")"
id="$(printf '%s' "$all" | jq -r --arg field "$ident_field" --arg name "$name" '.[] | select(.[$field]==$name) | .id')"
if [ -n "$id" ] && [ "$id" != "null" ]; then
echo "Updating $endpoint '$name' (id=$id)"
call PUT "$endpoint/$id?forceSave=true" "$json"
else
echo "Creating $endpoint '$name'"
call POST "$endpoint?forceSave=true" "$json"
fi
}
prune_resources() {
endpoint="$1"
ident_field="$2"
shift 2
keep_list="$(printf '%s\n' "$@" | jq -R . | jq -s .)"
resources="$(get_resources "$endpoint")"
printf '%s' "$resources" | jq -c '.[]' | while IFS= read -r client; do
name="$(printf '%s' "$client" | jq -r --arg field "$ident_field" '.[$field]')"
id="$(printf '%s' "$client" | jq -r '.id')"
found="$(printf '%s' "$keep_list" | jq -r --arg name "$name" 'index($name)')"
if [ "$found" = "null" ]; then
echo "Deleting extra $endpoint '$name' (id=$id)"
call DELETE "$endpoint/$id" || echo "failed to delete $name, continuing"
fi
done
}
delete_resource() {
endpoint="$1"
ident_field="$2"
name="$3"
id="$(get_resource_id "$endpoint" "$ident_field" "$name")"
if [ -n "$id" ]; then
echo "Deleting $endpoint '$name' (id=$id)"
call DELETE "$endpoint/$id" || echo "Failed to delete $name, continuing"
else
echo "No $endpoint resource named '$name' found - skipping"
fi
}

View File

@@ -11,61 +11,30 @@ let
hmConfig = config.home-manager.users.${user};
inherit (hmConfig.virtualisation.quadlet) containers volumes networks;
mkApp = type: name: shortName: urlBase: mediaFolderBase: {
mkApp = type: name: shortName: urlBase: port: mediaFolderBase: {
inherit
type
name
shortName
urlBase
port
mediaFolderBase
;
};
arrs = [
(mkApp "radarr" "Radarr" "radarr" "/manage/films" "/films")
(mkApp "radarr" "Radarr (UHD)" "radarr-uhd" "/manage/films/uhd" "/films")
(mkApp "radarr" "Radarr (Anime)" "radarr-anime" "/manage/anime/films" "/anime/films")
(mkApp "sonarr" "Sonarr" "sonarr" "/manage/shows" "/shows")
(mkApp "sonarr" "Sonarr (UHD)" "sonarr-uhd" "/manage/shows/uhd" "/shows")
(mkApp "sonarr" "Sonarr (Anime)" "sonarr-anime" "/manage/anime/shows" "/anime/shows")
(mkApp "radarr" "Radarr" "radarr" "/manage/films" 7878 "/films")
(mkApp "radarr" "Radarr (UHD)" "radarr-uhd" "/manage/films/uhd" 7878 "/films")
(mkApp "radarr" "Radarr (Anime)" "radarr-anime" "/manage/anime/films" 7878 "/anime/films")
(mkApp "sonarr" "Sonarr" "sonarr" "/manage/shows" 8989 "/shows")
(mkApp "sonarr" "Sonarr (UHD)" "sonarr-uhd" "/manage/shows/uhd" 8989 "/shows")
(mkApp "sonarr" "Sonarr (Anime)" "sonarr-anime" "/manage/anime/shows" 8989 "/anime/shows")
];
arrMapping = {
radarr = {
port = 7878;
prowlarr = {
implementation = "Radarr";
configContract = "RadarrSettings";
};
};
sonarr = {
port = 8989;
prowlarr = {
implementation = "Sonarr";
configContract = "SonarrSettings";
};
};
};
in
{
imports = [
(import ./prowlarr {
inherit
user
home
arrs
arrMapping
;
})
(import ./recyclarr {
inherit
user
home
arrs
arrMapping
;
})
(import ./prowlarr { inherit user home arrs; })
(import ./recyclarr { inherit user home arrs; })
];
home-manager.users.${user} = {
@@ -108,14 +77,17 @@ in
];
volumes =
let
setup = pkgs.writeTextFile {
name = "setup.sh";
postStart = pkgs.writeTextFile {
name = "post-start.sh";
executable = true;
text = builtins.readFile ./${arr.type}/setup.sh;
text = ''
${builtins.readFile ./common.sh}
${builtins.readFile ./${arr.type}/post-start.sh}
'';
};
in
[
"${setup}:/etc/${arr.type}/setup.sh:ro"
"${postStart}:/etc/${arr.type}/post-start.sh:ro"
"${volumes.${arr.shortName}.ref}:/var/lib/${arr.type}"
"/mnt/storage/private/storm/containers/storage/volumes/transmission-data/_data:/var/lib/transmission"
"/mnt/storage/private/storm/containers/storage/volumes/media/_data:/var/lib/media"

View File

@@ -2,7 +2,6 @@
user,
home,
arrs,
arrMapping,
}:
{
config,
@@ -15,6 +14,18 @@ let
selfPkgs = inputs.self.packages.${system};
hmConfig = config.home-manager.users.${user};
inherit (hmConfig.virtualisation.quadlet) containers volumes networks;
arrMapping = {
radarr = {
implementation = "Radarr";
configContract = "RadarrSettings";
};
sonarr = {
implementation = "Sonarr";
configContract = "SonarrSettings";
};
};
in
{
home-manager.users.${user} = {
@@ -34,7 +45,7 @@ in
(pkgs.formats.json { }).generate "${arr.shortName}.json" {
enable = true;
name = arr.name;
inherit (arrMapping.${arr.type}.prowlarr) implementation configContract;
inherit (arrMapping.${arr.type}) implementation configContract;
syncLevel = "fullSync";
fields = [
{
@@ -43,7 +54,7 @@ in
}
{
name = "baseUrl";
value = "http://${arr.shortName}:${builtins.toString arrMapping.${arr.type}.port}";
value = "http://${arr.shortName}:${builtins.toString arr.port}";
}
{
name = "apiKey";
@@ -82,15 +93,17 @@ in
];
volumes =
let
setup = pkgs.writeTextFile {
name = "setup.sh";
postStart = pkgs.writeTextFile {
name = "post-start.sh";
executable = true;
text = builtins.readFile ./setup.sh;
text = ''
${builtins.readFile ../common.sh}
${builtins.readFile ./post-start.sh}
'';
};
in
[
"${setup}:/etc/prowlarr/setup.sh:ro"
"${./indexers}:/etc/prowlarr/indexers:ro"
"${postStart}:/etc/prowlarr/post-start.sh:ro"
"${volumes.prowlarr.ref}:/var/lib/prowlarr"
]
++ builtins.map (

View File

@@ -1,19 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "1337x",
"fields": [
{
"name": "definitionFile",
"value": "1337x"
},
{
"name": "baseUrl",
"value": "https://1337x.to/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings",
"tags": [1]
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "Internet Archive",
"fields": [
{
"name": "definitionFile",
"value": "internetarchive"
},
{
"name": "baseUrl",
"value": "https://archive.org/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "LimeTorrents",
"fields": [
{
"name": "definitionFile",
"value": "limetorrents"
},
{
"name": "baseUrl",
"value": "https://www.limetorrents.lol/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,30 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "Nyaa.si",
"fields": [
{
"name": "definitionFile",
"value": "nyaasi"
},
{
"name": "baseUrl",
"value": "https://nyaa.si/"
},
{
"name": "sonarr_compatibility",
"value": true
},
{
"name": "strip_s01",
"value": true
},
{
"name": "radarr_compatibility",
"value": true
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "The Pirate Bay",
"fields": [
{
"name": "definitionFile",
"value": "thepiratebay"
},
{
"name": "baseUrl",
"value": "https://thepiratebay.org/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "TheRARBG",
"fields": [
{
"name": "definitionFile",
"value": "therarbg"
},
{
"name": "baseUrl",
"value": "https://therarbg.to/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "Torlock",
"fields": [
{
"name": "definitionFile",
"value": "torlock"
},
{
"name": "baseUrl",
"value": "https://www.torlock.com/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "TorrentDownload",
"fields": [
{
"name": "definitionFile",
"value": "torrentdownload"
},
{
"name": "baseUrl",
"value": "https://www.torrentdownload.info/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "Torrent Downloads",
"fields": [
{
"name": "definitionFile",
"value": "torrentdownloads"
},
{
"name": "baseUrl",
"value": "https://www.torrentdownloads.pro/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "YourBittorrent",
"fields": [
{
"name": "definitionFile",
"value": "yourbittorrent"
},
{
"name": "baseUrl",
"value": "https://yourbittorrent.com/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -1,19 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "kickasstorrents.to",
"fields": [
{
"name": "definitionFile",
"value": "kickasstorrents-to"
},
{
"name": "baseUrl",
"value": "https://kickass.torrentbay.st/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings",
"tags": [1]
}

View File

@@ -1,18 +0,0 @@
{
"enable": true,
"appProfileId": 1,
"priority": 25,
"name": "kickasstorrents.ws",
"fields": [
{
"name": "definitionFile",
"value": "kickasstorrents-ws"
},
{
"name": "baseUrl",
"value": "https://kickass.ws/"
}
],
"implementation": "Cardigann",
"configContract": "CardigannSettings"
}

View File

@@ -0,0 +1,122 @@
# shellcheck shell=sh
# shellcheck disable=SC2034
HOST="http://localhost:9696$URL_BASE"
# shellcheck disable=SC2034
API_SUBPATH="/api/v1"
build_transmission_payload() {
cat <<-EOF
{
"enable": true,
"protocol": "torrent",
"priority": 1,
"name": "Transmission",
"fields": [
{ "name": "host", "value": "transmission" },
{ "name": "port", "value": 9091 },
{ "name": "urlBase", "value": "" }
],
"categories": [],
"implementation": "Transmission",
"configContract": "TransmissionSettings"
}
EOF
}
build_tag_payload() {
cat <<-EOF
{
"label": "flaresolverr"
}
EOF
}
build_flaresolverr_payload() {
tag_id="$1"
cat <<EOF
{
"name": "FlareSolverr",
"fields": [
{ "name": "host", "value": "http://flaresolverr:8191/" },
{ "name": "requestTimeout", "value": 60 }
],
"implementation": "FlareSolverr",
"configContract": "FlareSolverrSettings",
"tags": [ $tag_id ]
}
EOF
}
build_cardigann_indexer_payload() {
name="$1"
priority="$2"
definition_file="$3"
base_url="$4"
extra_fields_json="$5"
tags_json="$6"
jq -n \
--arg name "$name" \
--argjson priority "$priority" \
--arg definition_file "$definition_file" \
--arg base_url "$base_url" \
--argjson extra_fields "${extra_fields_json:-[]}" \
--argjson tags "${tags_json:-[]}" '
{
enable: true,
appProfileId: 1,
priority: $priority,
name: $name,
fields: (
[
{ name: "definitionFile", value: $definition_file },
{ name: "baseUrl", value: $base_url }
] + $extra_fields
),
implementation: "Cardigann",
configContract: "CardigannSettings"
} + (if ($tags | length) > 0 then { tags: $tags } else {} end)
'
}
wait_for_api
try_forever upsert_resource "downloadclient" "name" "Transmission" "$(build_transmission_payload)"
prune_resources "downloadclient" "name" "Transmission"
insert_or_skip_resource "tag" "label" "flaresolverr" "$(build_tag_payload)"
flaresolverr_id="$(get_resource_id "tag" "label" "flaresolverr")"
try_forever upsert_resource "indexerProxy" "name" "FlareSolverr" "$(build_flaresolverr_payload "$flaresolverr_id")"
prune_resources "indexerProxy" "name" "FlareSolverr"
app_names=""
for filepath in /etc/prowlarr/apps/*.json; do
name="$(jq -r '.name' < "$filepath")"
json="$(cat "$filepath")"
try_forever upsert_resource "applications" "name" "$name" "$json"
app_names="$app_names \"$name\""
done
# shellcheck disable=SC2086
eval "prune_resources \"applications\" \"name\" $app_names"
try 5 upsert_resource "indexer" "name" "1337x" "$(build_cardigann_indexer_payload "1337x" 25 "1337x" "https://1337x.to/" "" "[$flaresolverr_id]")"
try 5 upsert_resource "indexer" "name" "Internet Archive" "$(build_cardigann_indexer_payload "Internet Archive" 25 "internetarchive" "https://archive.org/")"
try 5 upsert_resource "indexer" "name" "kickasstorrents.to" "$(build_cardigann_indexer_payload "kickasstorrents.to" 25 "kickasstorrents-to" "https://kickass.torrentbay.st/" "" "[$flaresolverr_id]")"
try 5 upsert_resource "indexer" "name" "kickasstorrents.ws" "$(build_cardigann_indexer_payload "kickasstorrents.ws" 25 "kickasstorrents-ws" "https://kickass.ws/")"
try 5 upsert_resource "indexer" "name" "LimeTorrents" "$(build_cardigann_indexer_payload "LimeTorrents" 25 "limetorrents" "https://www.limetorrents.lol/")"
try 5 upsert_resource "indexer" "name" "Nyaa.si" "$(build_cardigann_indexer_payload "Nyaa.si" 25 "nyaasi" "https://nyaa.si/" '[{"name":"sonarr_compatibility","value":true},{"name":"strip_s01","value":true},{"name":"radarr_compatibility","value":true}]')"
try 5 upsert_resource "indexer" "name" "The Pirate Bay" "$(build_cardigann_indexer_payload "The Pirate Bay" 25 "thepiratebay" "https://thepiratebay.org/")"
try 5 upsert_resource "indexer" "name" "TheRARBG" "$(build_cardigann_indexer_payload "TheRARBG" 25 "therarbg" "https://therarbg.to/")"
try 5 upsert_resource "indexer" "name" "Torlock" "$(build_cardigann_indexer_payload "Torlock" 25 "torlock" "https://www.torlock.com/")"
try 5 upsert_resource "indexer" "name" "TorrentDownload" "$(build_cardigann_indexer_payload "TorrentDownload" 25 "torrentdownload" "https://www.torrentdownload.info/")"
try 5 upsert_resource "indexer" "name" "Torrent Downloads" "$(build_cardigann_indexer_payload "Torrent Downloads" 25 "torrentdownloads" "https://www.torrentdownloads.pro/")"
try 5 upsert_resource "indexer" "name" "YourBittorrent" "$(build_cardigann_indexer_payload "YourBittorrent" 25 "yourbittorrent" "https://yourbittorrent.com/")"
prune_resources "indexer" "name" "1337x" "Internet Archive" "kickasstorrents.to" "kickasstorrents.ws" "LimeTorrents" "Nyaa.si" "The Pirate Bay" "TheRARBG" "Torlock" "TorrentDownload" "Torrent Downloads" "YourBittorrent"
prune_resources "tag" "label" "flaresolverr"

View File

@@ -1,81 +0,0 @@
# shellcheck shell=sh
# Tag ID: 1
curl -sf "$HOST/api/v1/tag" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-raw '{"label": "flaresolverr"}' || true
{
curl -sf --retry 5 "$HOST/api/v1/indexerProxy?forceSave=true" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-binary @- <<EOF
{
"name": "FlareSolverr",
"fields": [
{
"name": "host",
"value": "http://flaresolverr:8191/"
},
{
"name": "requestTimeout",
"value": 60
}
],
"implementation": "FlareSolverr",
"configContract": "FlareSolverrSettings",
"tags": [ 1 ]
}
EOF
} || true
{
curl -sf --retry 5 "$HOST/api/v1/downloadclient?forceSave=true" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-binary @- <<EOF
{
"enable": true,
"protocol": "torrent",
"priority": 1,
"name": "Transmission",
"fields": [
{
"name": "host",
"value": "transmission"
},
{
"name": "port",
"value": 9091
},
{
"name": "urlBase",
"value": ""
}
],
"categories": [],
"implementation": "Transmission",
"configContract": "TransmissionSettings"
}
EOF
} || true
for filepath in /etc/prowlarr/apps/*.json; do
curl -sf --retry 5 "$HOST/api/v1/applications?forceSave=true" \
-X POST \
-H "Content-Type: application/json" \
-H "X-Api-Key: $API_KEY" \
--data-binary @"$filepath" || true
done
for filepath in /etc/prowlarr/indexers/*.json; do
curl -sf --retry 10 "$HOST/api/v1/indexer?forceSave=true" \
-X POST \
-H "Content-Type: application/json" \
-H "X-Api-Key: $API_KEY" \
--data-binary @"$filepath" || true
done

View File

@@ -0,0 +1,58 @@
# shellcheck shell=sh
# shellcheck disable=SC2034
HOST="http://localhost:7878$URL_BASE"
# shellcheck disable=SC2034
API_SUBPATH="/api/v3"
DOWNLOAD_CATEGORY="${DOWNLOAD_CATEGORY:-radarr}"
build_transmission_payload() {
cat <<-EOF
{
"enable": true,
"protocol": "torrent",
"priority": 1,
"name": "Transmission",
"fields": [
{ "name": "host", "value": "transmission" },
{ "name": "port", "value": 9091 },
{ "name": "urlBase", "value": "" },
{ "name": "movieCategory", "value": "$DOWNLOAD_CATEGORY" }
],
"implementation": "Transmission",
"configContract": "TransmissionSettings"
}
EOF
}
build_rootfolder_payload() {
cat <<-EOF
{
"path": "$ROOT_FOLDER"
}
EOF
}
wait_for_api
if [ -n "$ROOT_FOLDER" ]; then
insert_or_skip_resource "rootfolder" "path" "$ROOT_FOLDER" "$(build_rootfolder_payload)"
prune_resources "rootfolder" "path" "$ROOT_FOLDER"
fi
try_forever upsert_resource "downloadclient" "name" "Transmission" "$(build_transmission_payload)"
prune_resources "downloadclient" "name" "Transmission"
delete_resource "qualityprofile" "name" "SD"
delete_resource "qualityprofile" "name" "HD-720p"
delete_resource "qualityprofile" "name" "HD-1080p"
delete_resource "qualityprofile" "name" "HD - 720p/1080p"
delete_resource "qualityprofile" "name" "Ultra-HD"
try_forever sh -c "[ $(get_resources qualityprofile | jq length) -eq 2 ]"
get_resources qualityprofile | jq -c '.[]' | while IFS= read -r profile; do
id="$(printf '%s' "$profile" | jq -r '.id')"
patched="$(printf '%s' "$profile" | jq '.language.id = -2 | .language.Name = "Original"')"
echo "Patching qualityprofile id=$id with language = Original"
call PUT "qualityprofile/$id?forceSave=true" "$patched"
done

View File

@@ -1,48 +0,0 @@
# shellcheck shell=sh
DOWNLOAD_CATEGORY="${DOWNLOAD_CATEGORY:-radarr}"
mkdir -p "/var/lib/transmission/$DOWNLOAD_CATEGORY"
{
curl -sf --retry 5 "$HOST/api/v3/downloadclient?forceSave=true" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-binary @- <<EOF
{
"enable": true,
"protocol": "torrent",
"priority": 1,
"name": "Transmission",
"fields": [
{
"name": "host",
"value": "transmission"
},
{
"name": "port",
"value": 9091
},
{
"name": "urlBase",
"value": ""
},
{
"name": "movieCategory",
"value": "$DOWNLOAD_CATEGORY"
}
],
"implementation": "Transmission",
"configContract": "TransmissionSettings"
}
EOF
} || true
if [ -n "${ROOT_FOLDER:-}" ]; then
curl -sf "$HOST/api/v3/rootfolder" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-raw "{\"path\": \"$ROOT_FOLDER\"}" || true
fi

View File

@@ -2,7 +2,6 @@
user,
home,
arrs,
arrMapping,
}:
{
config,
@@ -24,9 +23,7 @@ in
value.content = builtins.readFile (
(pkgs.formats.yaml { }).generate "${arr.shortName}.yaml" (
import ./apps/${arr.shortName}.nix {
base_url = "http://${arr.shortName}:${
builtins.toString arrMapping.${arr.type}.port
}${arr.urlBase}/";
base_url = "http://${arr.shortName}:${builtins.toString arr.port}${arr.urlBase}/";
api_key = hmConfig.sops.placeholder."${arr.shortName}/apiKey";
}
)

View File

@@ -0,0 +1,50 @@
# shellcheck shell=sh
# shellcheck disable=SC2034
HOST="http://localhost:8989$URL_BASE"
# shellcheck disable=SC2034
API_SUBPATH="/api/v3"
DOWNLOAD_CATEGORY="${DOWNLOAD_CATEGORY:-sonarr}"
build_transmission_payload() {
cat <<-EOF
{
"enable": true,
"protocol": "torrent",
"priority": 1,
"name": "Transmission",
"fields": [
{ "name": "host", "value": "transmission" },
{ "name": "port", "value": 9091 },
{ "name": "urlBase", "value": "" },
{ "name": "tvCategory", "value": "$DOWNLOAD_CATEGORY" }
],
"implementation": "Transmission",
"configContract": "TransmissionSettings"
}
EOF
}
build_rootfolder_payload() {
cat <<-EOF
{
"path": "$ROOT_FOLDER"
}
EOF
}
wait_for_api
if [ -n "$ROOT_FOLDER" ]; then
insert_or_skip_resource "rootfolder" "path" "$ROOT_FOLDER" "$(build_rootfolder_payload)"
prune_resources "rootfolder" "path" "$ROOT_FOLDER"
fi
try_forever upsert_resource "downloadclient" "name" "Transmission" "$(build_transmission_payload)"
prune_resources "downloadclient" "name" "Transmission"
delete_resource "qualityprofile" "name" "SD"
delete_resource "qualityprofile" "name" "HD-720p"
delete_resource "qualityprofile" "name" "HD-1080p"
delete_resource "qualityprofile" "name" "HD - 720p/1080p"
delete_resource "qualityprofile" "name" "Ultra-HD"

View File

@@ -1,48 +0,0 @@
# shellcheck shell=sh
DOWNLOAD_CATEGORY="${DOWNLOAD_CATEGORY:-sonarr}"
mkdir -p "/var/lib/transmission/$DOWNLOAD_CATEGORY"
{
curl -sf --retry 5 "$HOST/api/v3/downloadclient?forceSave=true" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-binary @- <<EOF
{
"enable": true,
"protocol": "torrent",
"priority": 1,
"name": "Transmission",
"fields": [
{
"name": "host",
"value": "transmission"
},
{
"name": "port",
"value": 9091
},
{
"name": "urlBase",
"value": ""
},
{
"name": "tvCategory",
"value": "$DOWNLOAD_CATEGORY"
}
],
"implementation": "Transmission",
"configContract": "TransmissionSettings"
}
EOF
} || true
if [ -n "${ROOT_FOLDER:-}" ]; then
curl -sf "$HOST/api/v3/rootfolder" \
-X POST \
-H 'Content-Type: application/json' \
-H "X-Api-Key: $API_KEY" \
--data-raw "{\"path\": \"$ROOT_FOLDER\"}" || true
fi