summaryrefslogtreecommitdiff
path: root/cleopatre/application/fw_wd/fwwatchd-clean
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/application/fw_wd/fwwatchd-clean')
-rwxr-xr-xcleopatre/application/fw_wd/fwwatchd-clean35
1 files changed, 35 insertions, 0 deletions
diff --git a/cleopatre/application/fw_wd/fwwatchd-clean b/cleopatre/application/fw_wd/fwwatchd-clean
new file mode 100755
index 0000000000..a28c87e458
--- /dev/null
+++ b/cleopatre/application/fw_wd/fwwatchd-clean
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+# Trace folder.
+TRACE_FOLDER=/usr/local/trace/
+# Trace basename.
+TRACE_BASENAME=trace_
+
+# Load personnalize preferences.
+test -f /etc/default/fwwatchd && . /etc/default/fwwatchd
+
+# Return true if traces use too much space.
+should_clean () {
+ if [[ -n "$TRACE_SIZE_LIMIT_KB" ]]; then
+ set -- $(du -ks "$TRACE_FOLDER")
+ [[ $1 -gt "$TRACE_SIZE_LIMIT_KB" ]] && return 0
+ fi
+ if [[ -n "$TRACE_FREE_LIMIT_KB" ]]; then
+ set -- $(df -k "$TRACE_FOLDER" | tail -n 1)
+ [[ $4 -lt "$TRACE_FREE_LIMIT_KB" ]] && return 0
+ fi
+ return 1
+}
+
+# Remove oldest trace, or return an error if nothing to remove.
+clean_oldest_trace () {
+ old_trace=$(ls -1 $TRACE_FOLDER/$TRACE_BASENAME[0-9]*.gz 2>/dev/null \
+ | sort -n -k 2 -t _ | head -n 1)
+ [[ -z "$old_trace" ]] && return 1
+ rm "$old_trace"
+}
+
+# Clean up old traces if needed.
+while should_clean; do
+ clean_oldest_trace || break
+done