#!/bin/bash

handle_shutdown() {
    echo "handler exec at $(date +%F_%X_%N) user: $USER, $HOME" >> $HOME/handler.log
    FILE=$HOME/.config/xfce4/xfconf/xfce-perchannel-xml/displays.xml
    su -c "rm $FILE" $USER || true
    CMD='sed -i "/^$(hostname) /d" $HOME/.client-logins.log'
    su -c "$CMD" $USER
    su -c "rm -f $HOME/.config/Thunar/uca.xml" $USER
    exit 0
}

# Intrappola i segnali SIGTERM
trap 'handle_shutdown' SIGTERM

echo "user: $USER, $(date +%F_%X_%N) in attesa di shutdown o reboot..." >> /var/log/session.log

sleep infinity

