Make user functions more robust

This commit is contained in:
2023-04-07 10:37:03 -04:00
parent 1bde2a2478
commit 49365cb712
3 changed files with 11 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Remove a user from the server
# Copyright 2021 Bryan C. Roessler
# Copyright 2021-2023 Bryan C. Roessler
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
@@ -23,15 +23,15 @@ if ! id -u "$user"; then
exit 1
fi
! ask_ok "Remove user $user?" && exit $?
ask_ok "Remove user $user?" || exit 1
killall -u "$user"
if ask_ok "Backup /home/$user?" && [[ -d /home/"$user" ]]; then
if [[ ! -d /mnt/array/home-retired/"$user" ]]; then
btrfs subvolume create /mnt/array/home-retired/"$user"
if ask_ok "Backup /home/$user?" && [[ -d /home/$user ]]; then
if [[ ! -d /mnt/array/home-retired/$user ]]; then
btrfs subvolume create /mnt/array/home-retired/"$user" || exit 1
fi
rsync -av /home/"$user"/ /mnt/array/home-retired/"$user"
rsync -av /home/"$user"/ /mnt/array/home-retired/"$user" || exit 1
fi
smbpasswd -x "$user"