mirror of
https://github.com/trailofbits/algo.git
synced 2025-07-13 09:13:01 +02:00
Add user management scripts for AlgoVPN (add and remove users)
This commit is contained in:
parent
346437fa6e
commit
198f98af44
2 changed files with 71 additions and 0 deletions
36
add-user.sh
Executable file
36
add-user.sh
Executable file
|
@ -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 <username>"
|
||||
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!"
|
||||
|
||||
|
35
remove-user.sh
Normal file
35
remove-user.sh
Normal file
|
@ -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 <username>"
|
||||
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!"
|
Loading…
Add table
Reference in a new issue