diff --git a/functions b/functions index 444d6120..cbec6d0b 100644 --- a/functions +++ b/functions @@ -9,13 +9,12 @@ ask_ok() { read -r -p "$* [y/N]: " response response=${response,,} - [[ ! "$response" =~ ^(yes|y)$ ]] && return 1 - return 0 + [[ "$response" =~ ^(yes|y)$ ]] } is_root() { user=$(whoami) - [[ $user != "root" ]] && echo "Script must be run with sudo rights!" && exit 1 + [[ $user != "root" ]] && echo "Script must be run with sudo" && exit 1 } diff --git a/script-user-add b/script-user-add index f0087e06..75511b56 100755 --- a/script-user-add +++ b/script-user-add @@ -26,15 +26,15 @@ fi ask_ok "Create user $username with password $password?" || exit $? restore="no" -if [[ -d /mnt/array/home-retired/"$username" ]]; then +if [[ -d /mnt/array/home-retired/$username ]]; then ask_ok "Restore user $username's files from /mnt/array/home-retired/$user?" && restore="yes" fi samba="no" -ask_ok "Enable shared file access for user $username?" && group_str="smbgrp," && samba="yes" +ask_ok "Enable shared file access for user $username?" && group_str="smbgrp" && samba="yes" ask_ok "Make user $username an admin?" && \ - group_str+="wheel" + group_str+=",wheel" useradd_cmd+=("-G" "$group_str") useradd_cmd+=("$username") diff --git a/script-user-remove b/script-user-remove index 0339fd4d..ccdc4f4e 100755 --- a/script-user-remove +++ b/script-user-remove @@ -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"