Browse Source

Added -y flag to removeperson to bypass confirmation

theo 2 years ago
parent
commit
c4987c82d3
1 changed files with 15 additions and 5 deletions
  1. 15 5
      removeperson

+ 15 - 5
removeperson

@@ -2,6 +2,12 @@
 . .env
 . funcs
 
+# Check if option -y is passed
+if [ "$1" = "-y" ]; then
+	confirmed="true"
+	shift
+fi
+
 uid=$1
 if user_exists $uid; then
     true
@@ -10,15 +16,19 @@ else
     exit 1
 fi
 
-read -p "Are you sure you want to delete user $uid [y/N] " a
+[ -z "$confirmed" ] && read -p "Are you sure you want to delete user $uid [y/N] " a
 
 case $a in
     y*|o* )
+	confirmed="true";;
+    *)
+	confirmed="false";;
+esac
+
+if [ $confirmed = "true" ]; then
 	if user_is_posix $uid; then 
 		ldapdelete $LDAPOPTS cn=$uid,$GROUPSDN
 		./removefromgroups $uid $(get_posixGroups $uid)
 	fi
-	ldapdelete $LDAPOPTS uid=$uid,$PEOPLEDN ;;
-    * )
-        exit;;
-esac
+	ldapdelete $LDAPOPTS uid=$uid,$PEOPLEDN
+fi