Added create user scripts

This commit is contained in:
2025-12-19 16:03:34 +02:00
parent 58e3cbc00b
commit 2501da1429
5 changed files with 175 additions and 0 deletions

66
remove_backup_user.sh Normal file
View File

@@ -0,0 +1,66 @@
#!/usr/bin/env bash
set -euo pipefail
# ===============================
# Load environment
# ===============================
ENV_FILE="./.env"
if [[ ! -f "$ENV_FILE" ]]; then
echo "ERROR: .env file not found. Cannot determine what to remove."
exit 1
fi
# shellcheck disable=SC1090
source "$ENV_FILE"
# ===============================
# Validate required variables
# ===============================
: "${BACKUP_USER:?missing}"
: "${WRAPPER_PATH:?missing}"
HOME_DIR="/home/$BACKUP_USER"
SUDOERS_FILE="/etc/sudoers.d/$BACKUP_USER"
echo "This will REMOVE the following:"
echo " user: $BACKUP_USER"
echo " home dir: $HOME_DIR"
echo " sudo rule: $SUDOERS_FILE"
echo " wrapper: $WRAPPER_PATH"
echo
read -rp "Type YES to continue: " CONFIRM
if [[ "$CONFIRM" != "YES" ]]; then
echo "Aborted."
exit 1
fi
# ===============================
# Remove SSH + user
# ===============================
if id "$BACKUP_USER" >/dev/null 2>&1; then
userdel -r "$BACKUP_USER"
echo "User $BACKUP_USER removed."
else
echo "User $BACKUP_USER does not exist. Skipping."
fi
# ===============================
# Remove sudoers rule
# ===============================
if [[ -f "$SUDOERS_FILE" ]]; then
rm -f "$SUDOERS_FILE"
echo "Removed sudoers file."
fi
# ===============================
# Remove wrapper
# ===============================
if [[ -f "$WRAPPER_PATH" ]]; then
rm -f "$WRAPPER_PATH"
echo "Removed wrapper script."
fi
echo
echo "Cleanup completed successfully."