Update scripts and deploy with gnu stow

This commit is contained in:
2025-06-11 20:56:19 -04:00
parent f66c7a03c2
commit 537f23077e
37 changed files with 903 additions and 677 deletions

47
scripts/script-user-remove Executable file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Remove a user from the server
# Copyright 2021-2025 Bryan C. Roessler
# Licensed under the Apache License, Version 2.0
p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1
is_root
echo "This script supports one optional argument, a username"
if [[ $# -eq 1 ]]; then
user="$1"
else
prompt user
fi
if ! id -u "$user" &>/dev/null; then
echo "User $user does not exist"
exit 1
fi
ask_ok "Remove user $user?" || exit 1
# Kill user processes
killall -u "$user"
# Optional backup
if ask_ok "Backup /home/$user?" && [[ -d /home/$user ]]; then
backup_dir="/mnt/array/home-retired/$user"
if [[ ! -d $backup_dir ]]; then
btrfs subvolume create "$backup_dir" || exit 1
fi
rsync -av "/home/$user/" "$backup_dir/" || exit 1
fi
# Remove from Samba and subuid/subgid
smbpasswd -x "$user"
sed -i "/^$user:/d" /etc/subuid
sed -i "/^$user:/d" /etc/subgid
# Remove user and home directory
if ! userdel -fr "$user"; then
ask_ok "Userdel failed, kill processes again and retry?" || exit 1
killall -u "$user" -s SIGKILL
userdel -fr "$user"
fi