#!/bin/bash
# lastact: arturo@2023-02-20
# desc: Scripts llamados por lightdm. Configurado en: /etc/lightdm/lightdm.conf.d/99-vitalinux-scripts-stopdisplay.conf

run_scripts() {
    local _PATH="$1"

    if [ -d "${_PATH}" ]; then
        for _FILE in "${_PATH}"/*.sh; do
            if [ -r "${_FILE}" ]; then
                # shellcheck source=/dev/null
                chmod +x "${_FILE}"
                "${_FILE}"
            fi
        done
    fi
}

FICHFUNCS="/usr/bin/vx-funcs-bash"
[ -f "${FICHFUNCS}" ] && . "${FICHFUNCS}" "null"

# 1) Preparamos la auditoria del servicio:
LOG="$(basename "${0}").log"
vx-log_xsession -o "${LOG}"

ASUNTO="VX-SCRIPTS-XSTOP"
DESC="Scripts de cierre de sesión gráfica Lightdm"
vx-echo_log_titulo1 "${ASUNTO}" "${DESC}"

DIR_SCRIPTS="/usr/share/vitalinux/postrun.d"
if [[ "$(whoami)" == "root" ]]; then
    # execute prerun scripts
    if test -d "${DIR_SCRIPTS}"; then
        run_scripts "${DIR_SCRIPTS}"
    fi
fi
