#!/bin/bash
set -e

# Set correct permissions (optional, modify as needed)
[ -f /usr/share/dbus-1/system.d/wifi_keeper.conf ] && chmod 644 /usr/share/dbus-1/system.d/wifi_keeper.conf

# Ensure WifiKeeper service is enabled (required for WiFi connection from login screen)
if [ -f /usr/lib/systemd/system/lightdm-kde-greeter-wifikeeper.service ]; then
    deb-systemd-helper enable lightdm-kde-greeter-wifikeeper.service >/dev/null 2>&1 || true
fi
[ -f /etc/lightdm/lightdm.conf.d/01-myconfig.conf ] && chmod 644 /etc/lightdm/lightdm.conf.d/01-myconfig.conf
[ -f /etc/lightdm/lightdm.conf.d/50-myconfig.conf ] && chmod 644 /etc/lightdm/lightdm.conf.d/50-myconfig.conf
[ -f /etc/polkit-1/rules.d/50-wifikeeper-restart.rules ] && chmod 644 /etc/polkit-1/rules.d/50-wifikeeper-restart.rules

# Clear lightdm QML/application cache so updated theme files are loaded
if [ -d /var/lib/lightdm/.cache ]; then
    rm -rf /var/lib/lightdm/.cache/* 2>/dev/null || true
fi

# Pick up new hicolor icons (zdirectory) for the greeter session
if command -v gtk-update-icon-cache >/dev/null 2>&1 && [ -d /usr/share/icons/hicolor ]; then
    gtk-update-icon-cache -q /usr/share/icons/hicolor 2>/dev/null || true
fi

#DEBHELPER#
