BastionGuard/data/scripts/enable-user-agents.sh
specialworld83 f0f913a209 Release 2.0
2026-07-15 10:52:22 +02:00

39 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# enable-user-agents.sh
# Abilita i servizi BastionGuard user-level per tutti gli utenti attivi
set -euo pipefail
SERVICES=(
"BastionGuard-useragent.service"
"BastionGuard-ransomware-alert.service"
"BastionGuard-ransomware-scanner.service"
)
echo "[BastionGuard] Abilitazione servizi user-level..."
# Ricarica le unit globali di sistema
systemctl daemon-reload || true
# Ciclo su tutte le sessioni attive
while read -r SID USERNAME; do
# ignora root o valori vuoti
if [[ -z "$SID" || -z "$USERNAME" || "$USERNAME" == "root" ]]; then
continue
fi
USER_ID=$(id -u "$USERNAME" 2>/dev/null || true)
if [[ -z "$USER_ID" ]]; then
continue
fi
echo "[BastionGuard] Sessione $SID utente $USERNAME (UID=$USER_ID)"
for svc in "${SERVICES[@]}"; do
echo "[BastionGuard] -> abilito $svc per $USERNAME"
runuser -l "$USERNAME" -c \
"systemctl --user daemon-reload; systemctl --user enable --now $svc" \
|| echo "[BastionGuard] ⚠ impossibile abilitare $svc per $USERNAME"
done
done < <(loginctl list-sessions --no-legend | awk '{print $1,$3}')
echo "[BastionGuard] Fine."