#!/bin/bash
set -e

case "$1" in
    configure)
        # Create necessary directories
        mkdir -p /etc/cybertection
        mkdir -p /var/lib/cybertection/vpn
        mkdir -p /var/log/cybertection

        # Set permissions
        chown -R root:root /etc/cybertection
        chown -R root:root /var/lib/cybertection
        chown -R root:root /var/log/cybertection
        chmod 750 /etc/cybertection
        chmod 750 /var/lib/cybertection
        chmod 755 /var/log/cybertection

        # Create default config if it doesn't exist
        if [ ! -f /etc/cybertection/vpn.conf ]; then
            cat > /etc/cybertection/vpn.conf << 'EOF'
# Cybertection VPN Configuration
[vpn]
enabled = true
auto_start = false
log_level = INFO
config_dir = /var/lib/cybertection/vpn
EOF
            chmod 600 /etc/cybertection/vpn.conf
        fi

        # Reload systemd daemon
        systemctl daemon-reload || true
        
        echo "Cybertection VPN installed successfully"
        echo "To start the service: sudo systemctl start cybertection-vpn"
        echo "To enable auto-start: sudo systemctl enable cybertection-vpn"
        ;;
esac

exit 0
