Last active
April 29, 2024 23:08
-
-
Save bonelifer/e0cb47bdc1edac739e46f760ddb56b59 to your computer and use it in GitHub Desktop.
Bash script to add a user to The Lounge IRC web client Docker container, reset an existing users password, or remove a current user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bash script to manage users in The Lounge IRC web client Docker container | |
# Function to add user to The Lounge IRC web client Docker container | |
add_user_to_container() { | |
local container_name=$1 # Name of the Docker container | |
local username=$2 # Username to be added to The Lounge | |
docker exec -it $container_name s6-setuidgid abc thelounge add $username | |
} | |
# Function to reset user password in The Lounge IRC web client Docker container | |
reset_user_password() { | |
local container_name=$1 # Name of the Docker container | |
local username=$2 # Username whose password needs to be reset | |
docker exec -it $container_name s6-setuidgid abc thelounge reset $username | |
} | |
# Function to remove user from The Lounge IRC web client Docker container | |
remove_user_from_container() { | |
local container_name=$1 # Name of the Docker container | |
local username=$2 # Username to be removed from The Lounge | |
echo -n "Are you sure you want to remove user $username from The Lounge? (y/n): " | |
read confirm_remove | |
if [ "$confirm_remove" != "y" ]; then | |
echo "User removal canceled." | |
exit 0 | |
fi | |
echo -n "Type 'yes' to confirm removal of user $username: " | |
read confirm_yes | |
if [ "$confirm_yes" != "yes" ]; then | |
echo "User removal canceled." | |
exit 0 | |
fi | |
docker exec -it $container_name s6-setuidgid abc thelounge remove $username | |
} | |
# Function to display usage information | |
usage() { | |
echo "Usage: $0 <option> <username>" | |
echo | |
echo "Options:" | |
echo " add Add a new user to The Lounge." | |
echo " reset Reset password for an existing user in The Lounge." | |
echo " remove Remove an existing user from The Lounge." | |
echo | |
echo "Arguments:" | |
echo " <username> Username of the user to be added, reset, or removed." | |
echo | |
echo "Examples:" | |
echo " $0 add john_doe" | |
echo " $0 reset jane_smith" | |
echo " $0 remove bob" | |
} | |
# Main function | |
main() { | |
# Check if option and username are provided as arguments | |
if [ $# -ne 2 ]; then | |
usage | |
exit 1 | |
fi | |
local option=$1 # Option: add, reset, or remove | |
local username=$2 # Username provided as an argument | |
local container_name="thelounge" # Name of The Lounge Docker container | |
case $option in | |
"add") | |
# Add user to The Lounge Docker container | |
add_user_to_container $container_name $username | |
echo "User $username has been added to The Lounge container." | |
;; | |
"reset") | |
# Reset user password in The Lounge Docker container | |
reset_user_password $container_name $username | |
echo "Password for user $username has been reset in The Lounge container." | |
;; | |
"remove") | |
# Remove user from The Lounge Docker container | |
remove_user_from_container $container_name $username | |
echo "User $username has been removed from The Lounge container." | |
;; | |
*) | |
echo "Invalid option: $option" | |
usage | |
exit 1 | |
;; | |
esac | |
} | |
# Call the main function with the provided arguments | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment