added manual neuclear option to arrs cleanup

This commit is contained in:
2026-04-26 01:05:22 -04:00
parent f826672b80
commit 3df4542351
11 changed files with 988 additions and 97 deletions
+53 -3
View File
@@ -31,6 +31,14 @@
# Required when deletion would exceed LIDARR_MAX_DELETE_GB
# Long and annoying by design — cannot be added accidentally
#
# --skip-strike-list flag:
# Bypasses the LIDARR_ORPHAN_AGE age check — deletes recent files too
# Combined with --i-know-what-im-doing activates NUCLEAR MODE:
# Age check bypassed, size threshold bypassed, deletes on first pass
# Use when Soularr/other tool has filled the gaps — clean one-pass wipe
# ⚠️ The script author takes NO responsibility for data loss with both flags active
# The user accepts full responsibility — this is 100% intentional by design
#
# Lidarr runs on HOST1 only — music library is HOST1's source of truth.
# If run on HOST2 this script exits cleanly with no action.
# All configuration in Master.conf under Arr Cleanup section.
@@ -42,12 +50,16 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# Check for --i-know-what-im-doing flag before parse_args
# Check for --i-know-what-im-doing and --skip-strike-list flags before parse_args
# These flags are filtered out before parse_args sees them to avoid unknown flag errors
I_KNOW=false
SKIP_STRIKES=false
FILTERED_ARGS=()
for arg in "$@"; do
if [[ "$arg" == "--i-know-what-im-doing" ]]; then
I_KNOW=true
elif [[ "$arg" == "--skip-strike-list" ]]; then
SKIP_STRIKES=true
else
FILTERED_ARGS+=("$arg")
fi
@@ -55,6 +67,32 @@ done
parse_args "${FILTERED_ARGS[@]}"
# Nuclear mode — both override flags active
# Strike system AND size threshold bypassed — deletes on first pass
# Script author takes no responsibility for data loss when both flags are used.
# This combination is 100% intentional and the user accepts full responsibility.
if [[ "$I_KNOW" == true ]] && [[ "$SKIP_STRIKES" == true ]] && [[ "$DRY_RUN" != true ]]; then
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "⚠️ WARNING — NUCLEAR MODE ACTIVE"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Flags: --i-know-what-im-doing --skip-strike-list"
echo " Strike system: BYPASSED — deletes on first pass"
echo " Size threshold: BYPASSED — no GB limit"
echo " Data recovery: NOT POSSIBLE after deletion"
echo ""
echo " The script author takes no responsibility for data"
echo " loss when both flags are used together. This is a"
echo " 100% intentional action by the user."
echo ""
echo " Review the dry run output before proceeding."
echo " You have 10 seconds to cancel (Ctrl+C)..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
sleep 10
echo " Proceeding..."
echo ""
fi
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_GEAR Setup ━━━
# -----------------------------------------------------------------------------------------------
@@ -117,6 +155,9 @@ if [[ ! -d "$LIDARR_MUSIC_ROOT" ]]; then
exit 1
fi
# Large library scans take time — override default lock warn age
[[ -n "${LIDARR_LOCK_WARN_AGE:-}" ]] && LOCK_WARN_AGE="$LIDARR_LOCK_WARN_AGE"
acquire_lock "wait"
# -----------------------------------------------------------------------------------------------
@@ -156,6 +197,7 @@ esac
success "All safety checks passed"
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no files will be deleted"
[[ "$I_KNOW" == true ]] && warn "OVERRIDE — --i-know-what-im-doing flag active"
[[ "$SKIP_STRIKES" == true ]] && warn "OVERRIDE — --skip-strike-list flag active — strike system bypassed"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
@@ -349,7 +391,7 @@ while IFS= read -r filepath; do
FILE_MTIME=$(stat -c %Y "$filepath" 2>/dev/null || echo 0)
FILE_AGE=$(( NOW - FILE_MTIME ))
if [[ "$FILE_AGE" -lt "$AGE_SECONDS" ]]; then
if [[ "$FILE_AGE" -lt "$AGE_SECONDS" ]] && [[ "$SKIP_STRIKES" != true ]]; then
log "RECENT (skipping): $filepath"
((RECENT_COUNT++))
continue
@@ -379,6 +421,7 @@ if [[ "$TOTAL_DELETE_BYTES" -gt "$MAX_DELETE_BYTES" ]]; then
error "Deletion would exceed ${LIDARR_MAX_DELETE_GB}GB threshold — $TOTAL_HUMAN would be deleted"
error "Review the ORPHAN lines above carefully before proceeding"
error "If this is expected, rerun with: --i-know-what-im-doing"
error "To also bypass age check and delete on first pass: add --skip-strike-list"
notify "Lidarr cleanup halted on $(hostname)${TOTAL_HUMAN} deletion requires --i-know-what-im-doing" "Lidarr Cleanup" "warning"
exit 1
else
@@ -398,7 +441,7 @@ if [[ "$DRY_RUN" == false ]]; then
FILE_AGE=$(( NOW - FILE_MTIME ))
if is_music_file "$filepath"; then
[[ "$FILE_AGE" -lt "$AGE_SECONDS" ]] && continue
[[ "$FILE_AGE" -lt "$AGE_SECONDS" ]] && [[ "$SKIP_STRIKES" != true ]] && continue
fi
rm -f "$filepath" 2>/dev/null || error "Failed to delete: $filepath"
@@ -448,4 +491,11 @@ else
echo "$ICON_DONE Status: $ICON_SUCCESS DONE — $TOTAL_REMOVED files removed (orphans: $ORPHAN_HUMAN junk: $JUNK_HUMAN)"
notify "Lidarr cleanup on $(hostname) — removed $TOTAL_REMOVED files (orphans: $ORPHAN_HUMAN junk: $JUNK_HUMAN)" "Lidarr Cleanup" "normal"
fi
# Write stats for sunday_morning_coffee_report.sh
if [[ "$DRY_RUN" == false ]] && [[ -n "${ARR_CLEANUP_STATS:-}" ]]; then
DATE=$(date '+%Y-%m-%d')
echo "${DATE}|lidarr|${ORPHAN_COUNT}|${ORPHAN_BYTES}|${JUNK_COUNT}|${JUNK_BYTES}|${RECENT_COUNT}|${TRACKED_COUNT}" \
>> "$ARR_CLEANUP_STATS" 2>/dev/null || true
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"