#!/bin/bash

# default 9 months
days=274

if [ -n "$(printf '%s\n' "$1" | sed 's/[0-9]//g')" ] || [ -z "$1" ]; then
	echo "No valid day count given, using default value of $days"
	echo ""
else
	days=$1
fi

echo "Purge data older than $days days"
echo ""

for box in 348 421 423 424 425 5001 5002 5004 5005 5006 5008 5009 5010 5011 5012 5013
do
	echo purge files for: $box mic0
	python3 purge_audio.py -d=$days -p=/store/audio/$box/mic0 -y
	echo purge links for: $box mic0
	find /store/audio-web/html/n/$box/mic0/ -xtype l -delete
	if [ -d /store/audio/$box/mic1 ]; then
                echo purge files for: $box mic1
                python3 purge_audio.py -d=$days -p=/store/audio/$box/mic1 -y
                echo purge links for: $box mic1
                find /store/audio-web/html/n/$box/mic1/ -xtype l -delete
        fi
	echo ""
done
