60 lines
1.7 KiB
Bash
Executable File
60 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# This script will reset x2go sessions to a working state
|
|
# Use --all to reset all user X2Go sessions
|
|
# Copyright Bryan C. Roessler
|
|
|
|
parent="${BASH_SOURCE[0]}"
|
|
parent=${parent%/*}
|
|
|
|
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
|
|
|
|
echo "This script supports one optional argument, a username (or --all for all users)"
|
|
|
|
USER_MODE=0
|
|
USER_LIST=()
|
|
if [[ $EUID -gt 0 ]]; then
|
|
echo "This script should normally be run as root (with sudo)"
|
|
echo "Attempting to run in user mode"
|
|
USER_MODE=1
|
|
USER_LIST+=($(whoami))
|
|
else
|
|
if [[ $# -eq 1 ]]; then
|
|
if [[ $1 == '--all' ]]; then
|
|
for i in /home/*; do
|
|
USER_LIST+=("${i##*/}")
|
|
done
|
|
else
|
|
USER_LIST+=("$1")
|
|
fi
|
|
else
|
|
prompt user
|
|
USER_LIST+=("$user")
|
|
unset user
|
|
fi
|
|
fi
|
|
|
|
for user in "${USER_LIST[@]}"; do
|
|
# Clean local user cache
|
|
shopt -s nullglob
|
|
caches=(/home/"$user"/.x2go/C-"$user"-* /home/"$user"/.xsession-x2go-*)
|
|
shopt -u nullglob
|
|
if [[ ${#caches} -gt 0 ]]; then
|
|
ask_ok "Remove X2Go cache files for user $user?" &&
|
|
rm -rf /home/"$user"/.x2go/C-"$user"-* &&
|
|
echo "Removed: ${caches[*]} for user $user"
|
|
fi
|
|
# Clean X2Go sessions
|
|
if (( USER_MODE )); then
|
|
mapfile -t sessions < <(x2golistsessions | grep "$user"| cut -f2 -d'|')
|
|
else
|
|
mapfile -t sessions < <(x2golistsessions_root | grep "$user"| cut -f2 -d'|')
|
|
fi
|
|
if [[ ${#sessions} -gt 0 ]]; then
|
|
ask_ok "Terminate X2Go sessions for user $user?" &&
|
|
for session in "${sessions[@]}"; do
|
|
x2goterminate-session "$session" &&
|
|
echo "Terminated: $session for user $user"
|
|
done
|
|
fi
|
|
done
|