users: Handle errors better during POSIX user operations

- If during an action, user does not exist ignore.

- If during an action, return a non-zero exist status.

- Catch an errors during actions as exceptions.

- Display a message that corresponding POSIX operation failed.
This commit is contained in:
Sunil Mohan Adapa committed 2015-01-25 01:45:51 +05:30
1 parent d27cd02193
commit a3de3ae277
9 files changed
+114 -35

No files matched your search

+1 -1
View File
@@ -30,5 +30,5 @@ fi
echo "$username:$password" | chpasswd
if [ $? -ne 0 ]; then
echo "Failed: could not set user password"
exit
exit 2
fi
+3 -3
View File
@@ -22,17 +22,17 @@ password="$2"
adduser --disabled-password --gecos "" "$username"
if [ $? -ne 0 ]; then
echo "Failed to create user"
exit
exit 1
fi
adduser "$username" sudo
if [ $? -ne 0 ]; then
echo "Failed to add user to sudo group"
exit
exit 2
fi
echo "$username:$password" | chpasswd
if [ $? -ne 0 ]; then
echo "Failed to set user password"
exit
exit 3
fi
+1
View File
@@ -31,4 +31,5 @@ if [ $? -eq 0 ]; then
echo "Success: user deleted"
else
echo "Failed: userdel error"
exit 2
fi
+7
View File
@@ -20,7 +20,14 @@
username="$1"
getent passwd "$username"
if [ $? -ne 0 ]; then
echo "Failed: user not found"
exit
fi
usermod --expiredate 1 "$username"
if [ $? -ne 0 ]; then
echo "Failed"
exit 2
fi
+7
View File
@@ -20,7 +20,14 @@
username="$1"
getent passwd "$username"
if [ $? -ne 0 ]; then
echo "Failed: user not found"
exit
fi
usermod --expiredate "" "$username"
if [ $? -ne 0 ]; then
echo "Failed"
exit 2
fi