Files
hartman-server/script-user-reset-password

39 lines
816 B
Bash
Executable File

#!/usr/bin/env bash
# This script will reset a user password on the server
# Copyright 2021-24 Bryan C. Roessler
unset user password
parent="${BASH_SOURCE[0]}"
parent=${parent%/*}
[[ -f "$parent"/script-functions ]] && . "$parent"/script-functions || exit 1
is_root
if [[ $# -eq 0 ]]; then
prompt username
prompt password
elif [[ $# -eq 1 ]]; then
username="$1"
prompt password
elif [[ $# -eq 2 ]]; then
username="$1"
password="$2"
elif [[ $# -gt 2 ]]; then
echo "Too many arguments provided"
exit 1
fi
if ! id -u "$username" &>/dev/null; then
echo "User $user does not exist"
exit 1
fi
if ask_ok "Change user $user's password to $password?"; then
echo "$user":"$password" | chpasswd
(echo "$password"; echo "$password") | smbpasswd -a -s "$user"
fi
exit 0