Refactor script-user-reset-x2go
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# This script will add scripts-* to the PATH and the manual to each user's desktop
|
# This script will add scripts-* to the PATH and the manual to each user's desktop
|
||||||
# Copyright 2021-2023 Bryan C. Roessler
|
# Copyright 2021-2024 Bryan C. Roessler
|
||||||
|
|
||||||
parent="${BASH_SOURCE[0]}"
|
parent="${BASH_SOURCE[0]}"
|
||||||
parent=${parent%/*}
|
parent=${parent%/*}
|
||||||
@@ -15,21 +15,19 @@ if [[ "$original_dir" != "$sourcedir" ]]; then
|
|||||||
pushd "$sourcedir" || exit $?
|
pushd "$sourcedir" || exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(( reload )) && [[ -f $parent/script-functions ]] && . "$parent"/script-functions
|
((reload)) && [[ -f $parent/script-functions ]] && . "$parent"/script-functions
|
||||||
|
|
||||||
is_root
|
|
||||||
|
|
||||||
target=/usr/local/bin
|
target=/usr/local/bin
|
||||||
for script in script-*; do
|
for script in script-*; do
|
||||||
echo "Installing $script to $target"
|
echo "Linking $script to $target"
|
||||||
[[ $script == "script-functions" ]] && install -m 644 "$script" "$target"
|
[[ $script == "script-functions" ]] && install -m 644 "$script" "$target"
|
||||||
cp -u "$script" "$target/"
|
sudo ln -s "$script" "$target/"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Install manual link
|
# Install manual link
|
||||||
remove=("manual.pdf" "manual.odt" "Notes.pdf" "Notes.odt"
|
remove=("manual.pdf" "manual.odt" "Notes.pdf" "Notes.odt"
|
||||||
"README.html" "Link to Manual.desktop" "manual-images"
|
"README.html" "Link to Manual.desktop" "manual-images"
|
||||||
"manual.html" "manual-images" "Manual.desktop" "manual.desktop")
|
"manual.html" "manual-images" "Manual.desktop" "manual.desktop")
|
||||||
for homedir in /home/*; do
|
for homedir in /home/*; do
|
||||||
desktop="$homedir/Desktop"
|
desktop="$homedir/Desktop"
|
||||||
[[ -d $desktop ]] || continue
|
[[ -d $desktop ]] || continue
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Generate a new QHTCP experiment directory
|
|
||||||
# Copyright 2024 Bryan C. Roessler
|
|
||||||
|
|
||||||
echo "This script supports one optional argument, a project name"
|
|
||||||
|
|
||||||
PROJECTS_DIR="/mnt/data/StudiesQHTCP"
|
|
||||||
TEMPLATE_DIR="/mnt/data/StudiesQHTCP/_TEMPLATE_2copy_rename_4every_new_QHTCPstudy_23_1001"
|
|
||||||
PROJECT_PREFIX="$(whoami)-$(date +%y-%m-%d)"
|
|
||||||
|
|
||||||
ask_project_name() { read -r -p "Enter a new project name: " PROJECT_NAME; }
|
|
||||||
|
|
||||||
if [[ $# == 1 ]]; then
|
|
||||||
PROJECT_NAME="$1"
|
|
||||||
else
|
|
||||||
ask_project_name
|
|
||||||
fi
|
|
||||||
|
|
||||||
PROJECT_DIR="$PROJECTS_DIR/$PROJECT_PREFIX-$PROJECT_NAME"
|
|
||||||
|
|
||||||
while [[ -d $PROJECT_DIR ]]; do
|
|
||||||
echo "A project already exists at $PROJECT_DIR"
|
|
||||||
ask_project_name
|
|
||||||
PROJECT_DIR="$PROJECTS_DIR/$PROJECT_PREFIX-$PROJECT_NAME"
|
|
||||||
done
|
|
||||||
|
|
||||||
if mkdir "$PROJECT_DIR" &&
|
|
||||||
cp -a "$TEMPLATE_DIR"/* "$PROJECT_DIR"; then
|
|
||||||
echo "New project created at $PROJECT_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3,29 +3,20 @@
|
|||||||
# Use --all to reset all user X2Go sessions
|
# Use --all to reset all user X2Go sessions
|
||||||
# Copyright Bryan C. Roessler
|
# Copyright Bryan C. Roessler
|
||||||
|
|
||||||
parent="${BASH_SOURCE[0]}"
|
parent="${BASH_SOURCE[0]%/*}"
|
||||||
parent=${parent%/*}
|
[[ -f $parent/script-functions ]] && . "$parent/script-functions" || exit 1
|
||||||
|
|
||||||
[[ -f $parent/script-functions ]] && . "$parent"/script-functions || exit 1
|
echo "Usage: $0 [username|--all]"
|
||||||
|
|
||||||
echo "This script supports one optional argument, a username (or --all for all users)"
|
|
||||||
|
|
||||||
USER_MODE=0
|
|
||||||
USER_LIST=()
|
USER_LIST=()
|
||||||
if [[ $EUID -gt 0 ]]; then
|
if [[ $EUID -gt 0 ]]; then
|
||||||
echo "This script should normally be run as root (with sudo)"
|
echo "Run as root for all users. Running in user mode for: $(whoami)"
|
||||||
echo "Attempting to run in user mode"
|
USER_LIST+=("$(whoami)")
|
||||||
USER_MODE=1
|
|
||||||
USER_LIST+=($(whoami))
|
|
||||||
else
|
else
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $1 == "--all" ]]; then
|
||||||
if [[ $1 == '--all' ]]; then
|
for d in /home/*; do [[ -d $d ]] && USER_LIST+=("${d##*/}"); done
|
||||||
for i in /home/*; do
|
elif [[ -n $1 ]]; then
|
||||||
USER_LIST+=("${i##*/}")
|
|
||||||
done
|
|
||||||
else
|
|
||||||
USER_LIST+=("$1")
|
USER_LIST+=("$1")
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
prompt user
|
prompt user
|
||||||
USER_LIST+=("$user")
|
USER_LIST+=("$user")
|
||||||
@@ -34,26 +25,27 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for user in "${USER_LIST[@]}"; do
|
for user in "${USER_LIST[@]}"; do
|
||||||
# Clean local user cache
|
# Remove X2Go cache files
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
caches=(/home/"$user"/.x2go/C-"$user"-* /home/"$user"/.xsession-x2go-*)
|
caches=(/home/"$user"/.x2go/C-"$user"-* /home/"$user"/.xsession-x2go-*)
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
if [[ ${#caches} -gt 0 ]]; then
|
if (( ${#caches[@]} )); then
|
||||||
ask_ok "Remove X2Go cache files for user $user?" &&
|
ask_ok "Remove X2Go cache files for $user?" &&
|
||||||
rm -rf /home/"$user"/.x2go/C-"$user"-* &&
|
rm -rf "${caches[@]}" &&
|
||||||
echo "Removed: ${caches[*]} for user $user"
|
echo "Removed: ${caches[*]} for $user"
|
||||||
fi
|
fi
|
||||||
# Clean X2Go sessions
|
|
||||||
if (( USER_MODE )); then
|
# Terminate X2Go sessions
|
||||||
mapfile -t sessions < <(x2golistsessions | grep "$user"| cut -f2 -d'|')
|
if [[ $EUID -gt 0 ]]; then
|
||||||
|
mapfile -t sessions < <(x2golistsessions | grep "$user" | cut -f2 -d'|')
|
||||||
else
|
else
|
||||||
mapfile -t sessions < <(x2golistsessions_root | grep "$user"| cut -f2 -d'|')
|
mapfile -t sessions < <(x2golistsessions_root | grep "$user" | cut -f2 -d'|')
|
||||||
fi
|
fi
|
||||||
if [[ ${#sessions} -gt 0 ]]; then
|
if (( ${#sessions[@]} )); then
|
||||||
ask_ok "Terminate X2Go sessions for user $user?" &&
|
ask_ok "Terminate X2Go sessions for $user?" &&
|
||||||
for session in "${sessions[@]}"; do
|
for session in "${sessions[@]}"; do
|
||||||
x2goterminate-session "$session" &&
|
x2goterminate-session "$session" &&
|
||||||
echo "Terminated: $session for user $user"
|
echo "Terminated: $session for $user"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user