progress on script
This commit is contained in:
parent
9ab09570af
commit
aea1e088e9
1 changed files with 23 additions and 6 deletions
|
@ -28,6 +28,7 @@ case "$1" in
|
||||||
Q1="CREATE SCHEMA if not exists usermgmt; use usermgmt; CREATE TABLE if not exists users (username varchar(255), name varchar(255), description varchar(255));"
|
Q1="CREATE SCHEMA if not exists usermgmt; use usermgmt; CREATE TABLE if not exists users (username varchar(255), name varchar(255), description varchar(255));"
|
||||||
SQL="${Q1}"
|
SQL="${Q1}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"add")
|
"add")
|
||||||
if [ $# -ne 4 ]
|
if [ $# -ne 4 ]
|
||||||
then
|
then
|
||||||
|
@ -37,7 +38,12 @@ case "$1" in
|
||||||
fi
|
fi
|
||||||
Q1="INSERT INTO usermgmt.users (username, name, description) VALUES ('$2', '$3', '$4');"
|
Q1="INSERT INTO usermgmt.users (username, name, description) VALUES ('$2', '$3', '$4');"
|
||||||
SQL="${Q1}"
|
SQL="${Q1}"
|
||||||
|
PASSWORD=`openssl rand -base64 12`
|
||||||
|
useradd -m -p "$PASSWORD" "$2"
|
||||||
|
echo "$PASSWORD" > "/home/$2/password.txt"
|
||||||
|
echo "This is your password. Please delete this file after saving the password." >> "/home/$2/password.txt"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"delete")
|
"delete")
|
||||||
if [ $# -ne 2 ]
|
if [ $# -ne 2 ]
|
||||||
then
|
then
|
||||||
|
@ -45,9 +51,19 @@ case "$1" in
|
||||||
echo "$USAGE"
|
echo "$USAGE"
|
||||||
exit $E_BADARGS
|
exit $E_BADARGS
|
||||||
fi
|
fi
|
||||||
|
echo -n "Are you sure you want to delete user "$2"? [y/N] "
|
||||||
|
read confirm
|
||||||
|
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]
|
||||||
|
then
|
||||||
Q1="DELETE FROM usermgmt.users WHERE username = '$2';"
|
Q1="DELETE FROM usermgmt.users WHERE username = '$2';"
|
||||||
SQL="${Q1}"
|
SQL="${Q1}"
|
||||||
|
userdel -r "$2"
|
||||||
|
else
|
||||||
|
echo "User deletion cancelled."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"list")
|
"list")
|
||||||
if [ $# -ne 1 ]
|
if [ $# -ne 1 ]
|
||||||
then
|
then
|
||||||
|
@ -58,6 +74,7 @@ case "$1" in
|
||||||
Q1="SELECT username, name, description FROM usermgmt.users;"
|
Q1="SELECT username, name, description FROM usermgmt.users;"
|
||||||
SQL="${Q1}"
|
SQL="${Q1}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Error: Invalid action. Please use a valid argument."
|
echo "Error: Invalid action. Please use a valid argument."
|
||||||
echo "$USAGE"
|
echo "$USAGE"
|
||||||
|
|
Reference in a new issue