Update custom scripts

This commit is contained in:
2025-07-24 03:06:41 -04:00
parent bff68aa4e1
commit 2adc5f5797
3 changed files with 20 additions and 27 deletions

View File

@@ -4,10 +4,10 @@
Type `sudo script-` and use tab completion to access the following helper programs. Type `sudo script-` and use tab completion to access the following helper programs.
* `sudo script-user-add <username> <password>` * `sudo script-user-add <username>`
* `sudo script-user-remove <username>` * `sudo script-user-remove <username>`
* Optionally backup the user home directory to the array before removal. * Optionally backup the user home directory to the array before removal.
* `sudo script-user-reset-password <username> <password>` * `sudo script-user-reset-password <username>`
* Reset a user's password if forgotten. * Reset a user's password if forgotten.
* `sudo script-user-reset-x2go <username>` * `sudo script-user-reset-x2go <username>`
* Completely reset the X2Go state for the user (destroys active/paused sessions). * Completely reset the X2Go state for the user (destroys active/paused sessions).

View File

@@ -4,7 +4,7 @@
# Licensed under the Apache License, Version 2.0 # Licensed under the Apache License, Version 2.0
p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1 p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1
echo "Usage: sudo $0 [username]" echo "Usage: sudo $0 <username>"
is_root is_root
@@ -63,8 +63,8 @@ ask_ok "Prompt user to reset password on next login?" &&
passwd --expire "$user" && passwd --expire "$user" &&
echo "NOTE: The file sharing (smbpasswd) will not be changed" echo "NOTE: The file sharing (smbpasswd) will not be changed"
# Copy manual to user desktop echo "User successfully created, provide them with the following for first login"
desktop="/home/$user/Desktop" echo "Username: $user"
mkdir -p "$desktop" echo "Password: $password"
exit 0 exit 0

View File

@@ -4,27 +4,14 @@
# Licensed under the Apache License, Version 2.0 # Licensed under the Apache License, Version 2.0
p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1 p="${BASH_SOURCE[0]%/*}"; [[ -r $p/script-functions ]] && . "$p"/script-functions || exit 1
echo "Usage: sudo $0 <username>"
is_root is_root
echo "Usage: $0 [username] [password]"
case $# in case $# in
0) 0) user=$(prompt user) ;;
prompt user 1) user="$1" ;;
prompt password *) echo "Too many arguments provided"; exit 1 ;;
;;
1)
user="$1"
prompt password
;;
2)
user="$1"
password="$2"
;;
*)
echo "Too many arguments provided"
exit 1
;;
esac esac
if ! id -u "$user" &>/dev/null; then if ! id -u "$user" &>/dev/null; then
@@ -32,13 +19,19 @@ if ! id -u "$user" &>/dev/null; then
exit 1 exit 1
fi fi
if ask_ok "Change user $user's password to $password?"; then # Generate random temporary password to provide to user
password=$(tr -dc 'A-HJ-NP-Za-km-z2-9' </dev/urandom | head -c12)
if ask_ok "Reset $user's password"; then
echo "$user:$password" | chpasswd echo "$user:$password" | chpasswd
(echo "$password"; echo "$password") | smbpasswd -a -s "$user" (echo "$password"; echo "$password") | smbpasswd -a -s "$user"
fi fi
ask_ok "Prompt user to reset password on next login?" && ask_ok "Prompt user to reset password on next login?" &&
passwd --expire "$user" && passwd --expire "$user"
echo "NOTE: The file sharing (smbpasswd) will not be changed"
echo "Password successfully reset for user $user, provide them with the following for login"
echo "Username: $user"
echo "Password: $password"
exit 0 exit 0