Browse Source

Added a script to create a group (and add an user to it)

Théo Ertzscheid 2 years ago
parent
commit
f16fc432ee
1 changed files with 42 additions and 0 deletions
  1. 42 0
      creategroup

+ 42 - 0
creategroup

@@ -0,0 +1,42 @@
+#!/bin/bash
+. .env
+. funcs
+
+# Check if option -p is passed, and if so prepare for a posixGroup creation
+if [ "$1" = "-p" ]; then
+	posix="true"
+	shift
+else
+	posix="false"
+fi
+
+cn="$1"
+
+if group_exists $cn; then
+    echo "Group $cn already exist." 
+    exit 1
+fi
+
+uid="$2"
+
+if user_exists $uid; then
+    true
+else
+    echo "User $uid does not exist." 
+    exit 1
+fi
+
+group="dn: cn=$cn,$GROUPSDN
+objectClass: top
+objectClass: groupOfNames
+cn: $cn"
+
+if [ $posix = "true" ] ; then
+	group=$(echo "$group
+gidNumber: $(get_posix_number)")
+fi
+
+group=$(echo "$group
+memberUid: $uid,$PEOPLEDN")
+
+echo "$group" #| ldapadd $LDAPOTS