#!/bin/bash
# Privacy log cleanup script
# Immediately cleans up existing logs and applies privacy settings
# Generated by Algo VPN privacy role

set -euo pipefail

echo "Starting privacy log cleanup..."

# Truncate existing log files to apply new rotation settings immediately
find /var/log -type f -name "*.log" -size +{{ privacy_log_rotation.max_size }}M -exec truncate -s {{ privacy_log_rotation.max_size }}M {} \; 2>/dev/null || true

# Remove old rotated logs that exceed our retention policy
find /var/log -type f \( -name "*.log.*" -o -name "*.gz" \) -mtime +{{ privacy_log_rotation.max_age }} -delete 2>/dev/null || true

# Clean up systemd journal to respect new settings
if [ -d /var/log/journal ]; then
    journalctl --vacuum-time={{ privacy_log_rotation.max_age }}d 2>/dev/null || true
    journalctl --vacuum-size={{ privacy_log_rotation.max_size * 10 }}M 2>/dev/null || true
fi

echo "Privacy log cleanup completed"
