| 1 |
#!/usr/bin/env bash |
| 2 |
# ========================================================================== |
| 3 |
# _ _ _ ____ ____ _____ |
| 4 |
# | | | (_) _ \ ___ _ __ / ___|___ _ _|_ _| __ __ _ ___ ___ _ __ |
| 5 |
# | |_| | | |_) / _ \ '__| | / _ \| '_ \| || '__/ _` |/ __/ _ \ '__| |
| 6 |
# | _ | | __/ __/ | | |__| (_) | | | | || | | (_| | (_| __/ | |
| 7 |
# |_| |_|_|_| \___|_| \____\___/|_| |_|_||_| \__,_|\___\___|_| |
| 8 |
# |
| 9 |
# --- High-Performance Connectivity Tracer (HiPerConTracer) --- |
| 10 |
# https://www.nntb.no/~dreibh/hipercontracer/ |
| 11 |
# ========================================================================== |
| 12 |
# |
| 13 |
# High-Performance Connectivity Tracer (HiPerConTracer) |
| 14 |
# Copyright (C) 2015-2026 by Thomas Dreibholz |
| 15 |
# |
| 16 |
# This program is free software: you can redistribute it and/or modify |
| 17 |
# it under the terms of the GNU General Public License as published by |
| 18 |
# the Free Software Foundation, either version 3 of the License, or |
| 19 |
# (at your option) any later version. |
| 20 |
# |
| 21 |
# This program is distributed in the hope that it will be useful, |
| 22 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
# GNU General Public License for more details. |
| 25 |
# |
| 26 |
# You should have received a copy of the GNU General Public License |
| 27 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 |
# |
| 29 |
# Contact: [email protected] |
| 30 |
|
| 31 |
# Bash options: |
| 32 |
set -eu |
| 33 |
|
| 34 |
|
| 35 |
# ###### Usage ############################################################## |
| 36 |
usage () { |
| 37 |
echo >&2 "Usage: $0 node_id [-h|--help] [-r|--remove-data]" |
| 38 |
exit 1 |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
# ###### Main program ####################################################### |
| 43 |
|
| 44 |
# ====== Handle arguments =================================================== |
| 45 |
if [ $# -lt 1 ] ; then |
| 46 |
usage |
| 47 |
fi |
| 48 |
|
| 49 |
NODE_ID="$1" |
| 50 |
shift |
| 51 |
|
| 52 |
if [[ ! "${NODE_ID}" =~ ^[0-9]+$ ]] ; then |
| 53 |
echo >&2 "ERROR: Invalid Node ID ${NODE_ID}!" |
| 54 |
exit 1 |
| 55 |
fi |
| 56 |
if [ "${NODE_ID}" -lt 1 ] || [ "${NODE_ID}" -gt 9999 ] ; then |
| 57 |
echo >&2 "ERROR: Invalid number for Node ID: ${NODE_ID}!" |
| 58 |
exit 1 |
| 59 |
fi |
| 60 |
|
| 61 |
GETOPT="$(PATH=/usr/local/bin:$PATH which getopt)" |
| 62 |
options="$(${GETOPT} -o hr --long help,remove-data -a -- "$@")" |
| 63 |
# shellcheck disable=SC2181 |
| 64 |
if [[ $? -ne 0 ]] ; then |
| 65 |
usage |
| 66 |
fi |
| 67 |
|
| 68 |
REMOVE_DATA=0 |
| 69 |
eval set -- "${options}" |
| 70 |
while [ $# -gt 0 ] ; do |
| 71 |
case "$1" in |
| 72 |
-h | --help) |
| 73 |
usage |
| 74 |
;; |
| 75 |
-r | --remove-data) |
| 76 |
REMOVE_DATA=1 |
| 77 |
shift |
| 78 |
;; |
| 79 |
--) |
| 80 |
shift |
| 81 |
break |
| 82 |
;; |
| 83 |
esac |
| 84 |
done |
| 85 |
|
| 86 |
|
| 87 |
# ====== Remove user ======================================================== |
| 88 |
user="node${NODE_ID}" |
| 89 |
echo -e "\x1b[34m$(date +"%Y-%m-%d %H:%M:%S") Deleting user ${user} ...\x1b[0m" |
| 90 |
|
| 91 |
if getent passwd "${user}" >/dev/null 2>&1; then |
| 92 |
echo "Deleting user ${user} ..." |
| 93 |
sudo userdel -r -f "${user}" || true |
| 94 |
fi |
| 95 |
if getent group "${user}" >/dev/null 2>&1; then |
| 96 |
echo "Deleting group ${user} ..." |
| 97 |
sudo groupdel "${user}" || true |
| 98 |
fi |
| 99 |
if [ ! -v SUDO_USER ] || [ "${SUDO_USER}" == "" ] ; then |
| 100 |
rm -f ~/keys/"${user}".pub ~/keys/"${user}".pub.new |
| 101 |
else |
| 102 |
rm -f /home/"${SUDO_USER}"/keys/"${user}".pub \ |
| 103 |
/home/"${SUDO_USER}"/keys/"${user}".pub.new |
| 104 |
fi |
| 105 |
if [ -d "/var/hipercontracer/data/${user}" ] ; then |
| 106 |
if [ ${REMOVE_DATA} -eq 1 ] ; then |
| 107 |
rm -rf "/var/hipercontracer/data/${user}" |
| 108 |
else |
| 109 |
echo "Keeping the data directory /var/hipercontracer/data/${user}, since data removal is not requested!" |
| 110 |
# The node user is not existing anymore; set ownership to "root" instead: |
| 111 |
sudo chown -R root:root "/var/hipercontracer/data/${user}" |
| 112 |
fi |
| 113 |
fi |
| 114 |
|
| 115 |
echo -e "\x1b[34m$(date +"%Y-%m-%d %H:%M:%S") Done.\x1b[0m" |