format script properly
This commit is contained in:
parent
758fab05df
commit
42b0869883
1 changed files with 20 additions and 25 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
E_BADARGS=65
|
E_BADARGS=65
|
||||||
MYSQL=`which mysql`
|
MYSQL=$(which mysql)
|
||||||
MYSQL_USER="root"
|
MYSQL_USER="root"
|
||||||
USAGE="
|
USAGE="
|
||||||
$0 -- user management script
|
$0 -- user management script
|
||||||
|
@ -16,8 +16,7 @@ Usage:
|
||||||
"
|
"
|
||||||
|
|
||||||
# Check for correct number of arguments and action
|
# Check for correct number of arguments and action
|
||||||
if [ $# -lt 1 ]
|
if [ $# -lt 1 ]; then
|
||||||
then
|
|
||||||
echo "$USAGE"
|
echo "$USAGE"
|
||||||
exit $E_BADARGS
|
exit $E_BADARGS
|
||||||
fi
|
fi
|
||||||
|
@ -30,31 +29,28 @@ case "$1" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"add")
|
"add")
|
||||||
if [ $# -ne 4 ]
|
if [ $# -ne 4 ]; then
|
||||||
then
|
|
||||||
echo "Error: Invalid action."
|
echo "Error: Invalid action."
|
||||||
echo "$USAGE"
|
echo "$USAGE"
|
||||||
exit $E_BADARGS
|
exit $E_BADARGS
|
||||||
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`
|
PASSWORD=$(openssl rand -base64 12)
|
||||||
useradd -m -p "$PASSWORD" -s /bin/bash "\$2"
|
useradd -m -p "$PASSWORD" -s /bin/bash "\$2"
|
||||||
echo "$PASSWORD" >"/home/\$2/password.txt"
|
echo "$PASSWORD" >"/home/\$2/password.txt"
|
||||||
echo "This is your password. Please delete this file after saving the 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
|
|
||||||
echo "Error: Invalid action."
|
echo "Error: Invalid action."
|
||||||
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] "
|
echo -n "Are you sure you want to delete user "$2"? [y/N] "
|
||||||
read confirm
|
read confirm
|
||||||
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]
|
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
|
||||||
then
|
|
||||||
Q1="DELETE FROM usermgmt.users WHERE username = '$2';"
|
Q1="DELETE FROM usermgmt.users WHERE username = '$2';"
|
||||||
SQL="${Q1}"
|
SQL="${Q1}"
|
||||||
userdel -r "$2"
|
userdel -r "$2"
|
||||||
|
@ -65,8 +61,7 @@ case "$1" in
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"list")
|
"list")
|
||||||
if [ $# -ne 1 ]
|
if [ $# -ne 1 ]; then
|
||||||
then
|
|
||||||
echo "Error: Invalid action."
|
echo "Error: Invalid action."
|
||||||
echo "$USAGE"
|
echo "$USAGE"
|
||||||
exit $E_BADARGS
|
exit $E_BADARGS
|
||||||
|
|
Reference in a new issue