From b54a7e50f3b12d4ba97e5a03102700c06f129884 Mon Sep 17 00:00:00 2001 From: VetheonGames Date: Fri, 24 May 2024 08:34:29 -0600 Subject: [PATCH] Create Add Users function --- InitMate.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/InitMate.sh b/InitMate.sh index 1c76b59..01feca1 100644 --- a/InitMate.sh +++ b/InitMate.sh @@ -135,6 +135,39 @@ run_additional_setup() { fi } +# Function to add additional users +add_users() { + log "Do you want to add additional users? (yes/no)" + read -r ADD_USERS + while [[ $ADD_USERS == "yes" ]]; do + log "Enter the username:" + read -r USERNAME + log "Enter the password:" + read -r -s PASSWORD + useradd -m "$USERNAME" + echo "$USERNAME:$PASSWORD" | chpasswd + + log "Do you want to grant sudo access to $USERNAME? (yes/no)" + read -r GRANT_SUDO + if [[ $GRANT_SUDO == "yes" ]]; then + usermod -aG sudo "$USERNAME" + log "$USERNAME has been granted sudo access." + fi + + log "Do you want to add a public key for $USERNAME? (yes/no)" + read -r ADD_PUBLIC_KEY + if [[ $ADD_PUBLIC_KEY == "yes" ]]; then + log "Please enter the public key:" + read -r PUBLIC_KEY + su - "$USERNAME" -c "mkdir -p ~/.ssh && echo '$PUBLIC_KEY' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh" + log "Public key added for $USERNAME." + fi + + log "Do you want to add another user? (yes/no)" + read -r ADD_USERS + done +} + # Main script execution detect_os log "Detected OS: $OS, Package Manager: $PKG_MANAGER" @@ -176,3 +209,6 @@ log "Setup complete. Summary of actions performed:" # Run additional setup if requested run_additional_setup + +# Add additional users if requested +add_users