Skip to content

Commit da485e1

Browse files
committed
Auto-wire Recyclarr and Unpackerr API keys
1 parent 8141de1 commit da485e1

4 files changed

Lines changed: 93 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ There are dozens of *arr stack Docker Compose repos on GitHub. Almost all of the
3333

3434
- **One command to install.** Clone, configure, and start everything with a single `curl | bash`. No 45-minute manual setup.
3535
- **Auto-configures itself.** The configure script wires up the core request/download stack via API (qBittorrent, Prowlarr, Radarr, Sonarr, Seerr). No clicking through those web UIs.
36+
- **Auto-wires keys.** The configure script also writes Radarr/Sonarr API keys into Recyclarr and Unpackerr automatically.
3637
- **Built for macOS.** Native paths, launchd instead of systemd, OrbStack or Docker Desktop instead of bare Docker. Not a Linux guide with "should work on Mac" in the footnotes.
3738
- **Self-healing.** Hourly health checks, download watchdog, VPN failover between providers. Runs unattended.
3839
- **Quality automation.** TRaSH Guides profiles filter out bad releases. Kometa keeps Plex metadata clean. Tdarr saves disk space with automatic transcoding.
@@ -187,7 +188,7 @@ Pre-configured templates in `configs/` (copy to your Media folder after first bo
187188
- **recyclarr.yml** - TRaSH Guides quality profiles for Radarr and Sonarr
188189
- **kometa.yml** - Plex metadata automation (franchise collections, resolution overlays)
189190

190-
Both require API keys that are generated on first boot. The configure script will print them for you.
191+
Recyclarr API keys are auto-injected by `scripts/configure.sh`. Kometa still needs your manual Plex token + TMDB API key.
191192

192193
## Music Setup
193194

SETUP.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you already have OrbStack (or Docker Desktop) and Plex installed, you can run
1414
curl -fsSL https://raw.githubusercontent.com/liamvibecodes/mac-media-stack-advanced/main/bootstrap.sh | bash
1515
```
1616

17-
It will prompt you for VPN keys, configure all services, and install automation jobs. You'll still need to do Step 7 (configure Recyclarr, Kometa, Tdarr, and Unpackerr with API keys) manually afterward.
17+
It will prompt you for VPN keys, configure all core services, auto-wire Recyclarr + Unpackerr API keys, and install automation jobs. You'll still need to do Step 7 for Kometa/Tdarr manual setup afterward.
1818

1919
To run from a local clone with custom paths:
2020

@@ -173,13 +173,8 @@ It also writes credentials/API keys to `<MEDIA_DIR>/state/first-run-credentials.
173173

174174
### Recyclarr (TRaSH quality profiles)
175175

176-
The setup script copied a template to `<MEDIA_DIR>/config/recyclarr/recyclarr.yml` (default: `~/Media/config/recyclarr/recyclarr.yml`). Open it and replace the API key placeholders with the keys printed by configure.sh:
177-
178-
```bash
179-
open -a TextEdit ~/Media/config/recyclarr/recyclarr.yml
180-
```
181-
182-
Replace `YOUR_SONARR_API_KEY` and `YOUR_RADARR_API_KEY`, then save.
176+
`scripts/configure.sh` now auto-injects your Sonarr/Radarr API keys into `<MEDIA_DIR>/config/recyclarr/recyclarr.yml` (default: `~/Media/config/recyclarr/recyclarr.yml`).
177+
You only need to review it if you want to customize profile behavior.
183178

184179
Recyclarr runs automatically at 3am daily. To trigger a manual sync:
185180
```bash
@@ -208,14 +203,8 @@ Replace `YOUR_PLEX_TOKEN` and `YOUR_TMDB_API_KEY`, then save.
208203

209204
### Unpackerr
210205

211-
Update `.env` with your Radarr and Sonarr API keys:
212-
```bash
213-
open -a TextEdit .env
214-
```
215-
Fill in `UN_SONARR_0_API_KEY` and `UN_RADARR_0_API_KEY`, then restart:
216-
```bash
217-
docker compose restart unpackerr
218-
```
206+
`scripts/configure.sh` now auto-writes `UN_SONARR_0_API_KEY` and `UN_RADARR_0_API_KEY` in `.env` and restarts Unpackerr.
207+
No manual edit is required unless you want to override defaults.
219208

220209
---
221210

bootstrap.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,13 @@ echo " Media location: $MEDIA_DIR"
272272
echo ""
273273
echo " Remaining manual steps:"
274274
echo " 1. Set up Plex libraries (Movies: $MEDIA_DIR/Movies, TV: $MEDIA_DIR/TV Shows)"
275-
echo " 2. Edit $MEDIA_DIR/config/recyclarr/recyclarr.yml with your API keys"
276-
echo " 3. Edit $MEDIA_DIR/config/kometa/config.yml with Plex token + TMDB key"
277-
echo " 4. Update .env with Unpackerr API keys, then: docker compose restart unpackerr"
278-
echo " 5. Configure Tdarr at http://localhost:8265"
275+
echo " 2. Edit $MEDIA_DIR/config/kometa/config.yml with Plex token + TMDB key"
276+
echo " 3. Configure Tdarr at http://localhost:8265"
279277
echo ""
280278
echo " Optional - Music (Lidarr + Tidarr):"
281279
echo " bash scripts/setup-music.sh"
282280
echo " docker compose --profile music up -d"
283281
echo " Then open http://localhost:8484 to authenticate with Tidal"
284282
echo ""
285-
echo " API keys were printed by the configure step above. Scroll up if needed."
283+
echo " API keys were printed and Recyclarr/Unpackerr were auto-wired by configure.sh."
286284
echo ""

scripts/configure.sh

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,81 @@ EOF
6969
chmod 600 "$CREDS_FILE"
7070
}
7171

72+
set_env_key() {
73+
local key="$1"
74+
local value="$2"
75+
local file="$3"
76+
local safe_value
77+
78+
if [[ ! -f "$file" ]]; then
79+
return 1
80+
fi
81+
82+
safe_value="${value//\\/\\\\}"
83+
safe_value="${safe_value//&/\\&}"
84+
85+
if grep -q "^${key}=" "$file"; then
86+
sed -i '' "s|^${key}=.*|${key}=${safe_value}|" "$file"
87+
else
88+
printf '\n%s=%s\n' "$key" "$value" >> "$file"
89+
fi
90+
}
91+
92+
wire_recyclarr_keys() {
93+
local recyclarr_cfg="$MEDIA_DIR/config/recyclarr/recyclarr.yml"
94+
local tmp
95+
96+
if [[ ! -f "$recyclarr_cfg" ]]; then
97+
warn "Recyclarr config not found at $recyclarr_cfg (skipping key injection)"
98+
return 0
99+
fi
100+
101+
tmp="$(mktemp)"
102+
awk -v sonarr_key="$SONARR_KEY" -v radarr_key="$RADARR_KEY" '
103+
/^sonarr:/ {section="sonarr"}
104+
/^radarr:/ {section="radarr"}
105+
{
106+
if (section=="sonarr" && $0 ~ /^[[:space:]]+api_key:[[:space:]]*/) {
107+
print " api_key: " sonarr_key
108+
next
109+
}
110+
if (section=="radarr" && $0 ~ /^[[:space:]]+api_key:[[:space:]]*/) {
111+
print " api_key: " radarr_key
112+
next
113+
}
114+
print
115+
}
116+
' "$recyclarr_cfg" > "$tmp"
117+
mv "$tmp" "$recyclarr_cfg"
118+
log "Recyclarr API keys written to $recyclarr_cfg"
119+
}
120+
121+
wire_unpackerr_keys() {
122+
local env_file="$SCRIPT_DIR/.env"
123+
local unpackerr_state
124+
125+
if ! set_env_key "UN_SONARR_0_API_KEY" "$SONARR_KEY" "$env_file"; then
126+
warn "Could not update UN_SONARR_0_API_KEY in $env_file"
127+
return 0
128+
fi
129+
if ! set_env_key "UN_RADARR_0_API_KEY" "$RADARR_KEY" "$env_file"; then
130+
warn "Could not update UN_RADARR_0_API_KEY in $env_file"
131+
return 0
132+
fi
133+
log "Unpackerr API keys updated in .env"
134+
135+
unpackerr_state=$(docker inspect -f '{{.State.Status}}' unpackerr 2>/dev/null || true)
136+
if [[ "$unpackerr_state" == "running" || "$unpackerr_state" == "created" || "$unpackerr_state" == "restarting" ]]; then
137+
if docker compose restart unpackerr >/dev/null 2>&1; then
138+
log "Unpackerr restarted to apply new API keys"
139+
else
140+
warn "Unpackerr restart failed; run 'docker compose restart unpackerr' manually"
141+
fi
142+
else
143+
warn "Unpackerr container not found/running; start stack then run 'docker compose restart unpackerr'"
144+
fi
145+
}
146+
72147
api_post_json() {
73148
local label="$1"
74149
local url="$2"
@@ -176,6 +251,11 @@ PROWLARR_KEY=$(get_api_key "prowlarr")
176251
log "Prowlarr API key: ${PROWLARR_KEY:0:8}..."
177252
echo ""
178253

254+
echo -e "${CYAN}[*] Wiring advanced configs...${NC}"
255+
wire_recyclarr_keys
256+
wire_unpackerr_keys
257+
echo ""
258+
179259
# 3. Configure qBittorrent
180260
echo -e "${CYAN}[3/6] Configuring qBittorrent...${NC}"
181261
echo ""
@@ -324,9 +404,9 @@ echo " Sonarr API Key: $SONARR_KEY"
324404
echo " Prowlarr API Key: $PROWLARR_KEY"
325405
echo " Saved credentials: $CREDS_FILE"
326406
echo ""
327-
echo -e " ${YELLOW}Save these!${NC} You'll need the API keys for:"
328-
echo " - configs/recyclarr.yml (copy to $MEDIA_DIR/config/recyclarr/)"
329-
echo " - .env (UN_SONARR_0_API_KEY and UN_RADARR_0_API_KEY for Unpackerr)"
407+
echo -e " ${YELLOW}Auto-wired:${NC} Recyclarr + Unpackerr API keys"
408+
echo " Remaining manual keys:"
409+
echo " - $MEDIA_DIR/config/kometa/config.yml (PLEX_TOKEN, TMDB API key)"
330410
echo ""
331411
echo " Seerr: http://localhost:5055"
332412
echo " Plex: http://localhost:32400/web"

0 commit comments

Comments
 (0)