#!/usr/bin/env bash scriptVersion="1.8" scriptName="Recyclarr" #### Import Settings source /config/extended.conf #### Import Functions source /config/extended/functions #### Create Log File logfileSetup # Redirect all output to a temporary log file to avoid duplicate logs exec &> >(tee -a /tmp/recyclarr_temp.log) #### Check Arr App getArrAppInfo verifyApiAccess verifyConfig () { if [ "$enableRecyclarr" != "true" ]; then log "Script is not enabled, enable by setting enableRecyclarr to \"true\" by modifying the \"/config/extended.conf\" config file..." log "Sleeping (infinity)" sleep infinity fi if [ -z "$recyclarrScriptInterval" ]; then recyclarrScriptInterval="6h" fi } RecyclarrProcess () { # Configure Yaml with URL and API Key sed -i "s%arrUrl%$arrUrl%g" "/config/extended/recyclarr.yaml" sed -i "s%arrApi%$arrApiKey%g" "/config/extended/recyclarr.yaml" # Update arr app log "Updating Arr via Recyclarr" if [ ! -d /config/extended/recyclarr-data ]; then mkdir -p /config/extended/recyclarr-data chmod 777 /config/extended/recyclarr-data fi # Run Recyclarr and capture the output /recyclarr/recyclarr sync -c $recyclarrConfig --app-data /config/extended/recyclarr-data 2>&1 | while IFS= read -r line; do log "$line" done log "Complete" } # Move the temporary log file to the final log file move_logs() { while IFS= read -r line; do echo "$(date "+%F %T") :: $scriptName :: $scriptVersion :: $line" >> "/config/logs/$logFileName" done < /tmp/recyclarr_temp.log rm /tmp/recyclarr_temp.log } # Loop Script for (( ; ; )); do let i++ logfileSetup verifyConfig getArrAppInfo verifyApiAccess RecyclarrProcess log "Script sleeping for $recyclarrScriptInterval..." sleep $recyclarrScriptInterval move_logs done exit