Script to add users

In my Vikunja installation on Docker, I don’t want just anyone to enter and register, but the interface doesn’t have any simple area from which to manage the users who are already registered or to register new users.

So I’ve opted to create a small script to register new users, delete users who were registered, and list users. Maybe it can be useful to someone. I’ll leave it here for you.

#!/bin/bash

# Function to list users
list_users() {
    echo "User list:"
    docker exec vikunja_api /app/vikunja/vikunja user list
}

# Function to create a user
create_user() {
    # Prompt the user for the username
    read -p "Enter the username: " username

    # Prompt the user for the password (without showing it on the screen)
    read -sp "Enter the password: " password
    echo

    # Prompt the user for the email address
    read -p "Enter the email address: " email

    # Execute the docker command with the values provided by the user
    docker exec vikunja_api /app/vikunja/vikunja user create -e "$email" -p "$password" -u "$username"
}

# Function to delete a user
delete_user() {
    # List users to display the IDs
    list_users

    # Prompt the user for the ID of the user to delete
    read -p "Enter the ID of the user you want to delete: " userID

    # Execute the docker command to delete the user with the provided ID
    docker exec vikunja_api /app/vikunja/vikunja user delete "$userID" -c -n
}

# Main function
main() {
    while true; do
        echo "What action would you like to perform?"
        echo "1. List users"
        echo "2. Create user"
        echo "3. Delete user"
        echo "4. Exit"

        read -p "Enter the number of the action you want to perform: " option

        case $option in
            1)
                list_users
                ;;
            2)
                create_user
                ;;
            3)
                delete_user
                ;;
            4)
                echo "Exiting the program."
                exit 0
                ;;
            *)
                echo "Invalid option. Please select a valid option."
                ;;
        esac
    done
}

# Call to the main function
main