diff --git a/add-user.sh b/add-user.sh new file mode 100755 index 0000000..5f81ac8 --- /dev/null +++ b/add-user.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# run +# chmod +x ./add-user.sh +# ./add-user.sh example + +# Checks if the username was passed as an argument +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +USERNAME=$1 + +# Define the path to the configuration file +CONFIG_FILE="./config.cfg" + +# Check if the configuration file exists +if [ ! -f "$CONFIG_FILE" ]; then + echo "Configuration file not found: $CONFIG_FILE" + exit 1 +fi + +# Check if the user is already in the config.cfg file +if grep -q " - $USERNAME" "$CONFIG_FILE"; then + echo "User $USERNAME is already in the configuration file." +else + echo "Adding user $USERNAME to the configuration file..." + # Add the user to the end of the user list + sed -i "/users:/a \ - $USERNAME" "$CONFIG_FILE" + ./algo update-users +fi + +echo "User Added!" + + diff --git a/remove-user.sh b/remove-user.sh new file mode 100644 index 0000000..68884e6 --- /dev/null +++ b/remove-user.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# run +# chmod +x ./remove-user.sh +# ./remove-user.sh example + +# Checks if the username was passed as an argument +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +USERNAME=$1 + +# Define the path to the configuration file +CONFIG_FILE="./config.cfg" + +# Check if the configuration file exists +if [ ! -f "$CONFIG_FILE" ]; then + echo "Configuration file not found: $CONFIG_FILE" + exit 1 +fi + +# Check if the user is already in the config.cfg file +if grep -q " - $USERNAME" "$CONFIG_FILE"; then + echo "Removing user $USERNAME from the configuration file..." + # Remove the user from the user list + sed -i "/ - $USERNAME/d" "$CONFIG_FILE" + echo "User $USERNAME successfully removed." +else + echo "User $USERNAME not found in the configuration file." + ./algo update-users +fi + +echo "User Removed!" \ No newline at end of file