#!/bin/bash

ACTION=$1
USERNAME=$2
PASSWORD=$3
NEW_PASSWORD=$4

if [ -z "$USERNAME" ]; then
    exit 1
fi

case "$ACTION" in
    add)
        #useradd -m --badnames "$USERNAME"
        useradd -m "$USERNAME"
        if [ $? -eq 0 ]; then
            echo "$USERNAME:$PASSWORD" | chpasswd
        fi
        ;;
    modify)
        echo "$USERNAME:$NEW_PASSWORD" | chpasswd
        ;;
    delete)
        userdel -rf "$USERNAME"
        ;;
    restart)
        systemctl restart radiusd
        ;;
    *)
        exit 1
        ;;
esac

