diff --git a/script-install-manual-scripts b/script-install-manual-scripts index 9cd1d9f8..18ea4a57 100755 --- a/script-install-manual-scripts +++ b/script-install-manual-scripts @@ -1,6 +1,6 @@ #!/usr/bin/env bash # 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=${parent%/*} @@ -15,21 +15,19 @@ if [[ "$original_dir" != "$sourcedir" ]]; then pushd "$sourcedir" || exit $? fi -(( reload )) && [[ -f $parent/script-functions ]] && . "$parent"/script-functions - -is_root +((reload)) && [[ -f $parent/script-functions ]] && . "$parent"/script-functions target=/usr/local/bin for script in script-*; do - echo "Installing $script to $target" + echo "Linking $script to $target" [[ $script == "script-functions" ]] && install -m 644 "$script" "$target" - cp -u "$script" "$target/" + sudo ln -s "$script" "$target/" done # Install manual link remove=("manual.pdf" "manual.odt" "Notes.pdf" "Notes.odt" -"README.html" "Link to Manual.desktop" "manual-images" -"manual.html" "manual-images" "Manual.desktop" "manual.desktop") + "README.html" "Link to Manual.desktop" "manual-images" + "manual.html" "manual-images" "Manual.desktop" "manual.desktop") for homedir in /home/*; do desktop="$homedir/Desktop" [[ -d $desktop ]] || continue diff --git a/script-qhtcp-new-project b/script-qhtcp-new-project deleted file mode 100755 index 0a833d57..00000000 --- a/script-qhtcp-new-project +++ /dev/null @@ -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 - - diff --git a/script-user-reset-x2go b/script-user-reset-x2go index 4e442467..f8450bc4 100755 --- a/script-user-reset-x2go +++ b/script-user-reset-x2go @@ -3,29 +3,20 @@ # Use --all to reset all user X2Go sessions # Copyright Bryan C. Roessler -parent="${BASH_SOURCE[0]}" -parent=${parent%/*} +parent="${BASH_SOURCE[0]%/*}" +[[ -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=() 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)) + echo "Run as root for all users. Running in user mode for: $(whoami)" + 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 + if [[ $1 == "--all" ]]; then + for d in /home/*; do [[ -d $d ]] && USER_LIST+=("${d##*/}"); done + elif [[ -n $1 ]]; then + USER_LIST+=("$1") else prompt user USER_LIST+=("$user") @@ -34,26 +25,27 @@ else fi for user in "${USER_LIST[@]}"; do - # Clean local user cache + # Remove X2Go cache files 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" + if (( ${#caches[@]} )); then + ask_ok "Remove X2Go cache files for $user?" && + rm -rf "${caches[@]}" && + echo "Removed: ${caches[*]} for $user" fi - # Clean X2Go sessions - if (( USER_MODE )); then - mapfile -t sessions < <(x2golistsessions | grep "$user"| cut -f2 -d'|') + + # Terminate X2Go sessions + if [[ $EUID -gt 0 ]]; then + mapfile -t sessions < <(x2golistsessions | grep "$user" | cut -f2 -d'|') else - mapfile -t sessions < <(x2golistsessions_root | grep "$user"| cut -f2 -d'|') + mapfile -t sessions < <(x2golistsessions_root | grep "$user" | cut -f2 -d'|') fi - if [[ ${#sessions} -gt 0 ]]; then - ask_ok "Terminate X2Go sessions for user $user?" && + if (( ${#sessions[@]} )); then + ask_ok "Terminate X2Go sessions for $user?" && for session in "${sessions[@]}"; do x2goterminate-session "$session" && - echo "Terminated: $session for user $user" + echo "Terminated: $session for $user" done fi done