Zarafa create user script for the DB plugin

From Zarafa wiki

(Difference between revisions)
Jump to: navigation, search
(Created page with "The Zarafa create user script. This is a script that can be used to create users in a more friendly way for people who are new to Linux. The script will ask what values you wan...")
Line 16: Line 16:
<pre>
<pre>
-
#/env/bin!
+
#!/usr/bin/env bash
-
# script to create a user in Zarafa with the DB user plugin.
+
# Script to create a user in Zarafa with the DB user plugin.
-
echo 'creating a new users. awnser the questions'
+
# Version (date / time): 20110107-13:00
 +
#
 +
# WARNING: DO NOT use this script when using the UNIX, LDAP or
 +
# Active Directory plugin!
 +
echo 'This script will help you creating a new Zarafa user.'
 +
echo 'DISCLAIMER: This script is only suitable for use with the DB plugin.'
 +
echo 'Creating a new Zarafa user. Please enter the details of the user.'
 +
 
 +
# Check if the user is root (required to run the zarafa-admin tool).
 +
if [ $USER != 'root' ]
 +
then
 +
echo
 +
echo "You need root privileges to run this script. Exiting."
 +
exit 0
 +
fi
#The user name. Input needed is the user name.
#The user name. Input needed is the user name.
-
echo 'user name'
+
echo
-
read username
+
while [ -z $username ] ;do
 +
echo -n 'User name of the new user:'
 +
read username
 +
done
#The password.
#The password.
-
echo 'password'
+
while [ -z $password ] ;do
-
read password
+
      echo -n 'Password (will not be visible on input):'
 +
read -s password
 +
echo ' '
 +
done
#The full name. No " "  needed for full names with spaces
#The full name. No " "  needed for full names with spaces
-
echo 'full name'
+
while [ -z $full ] ;do
-
read full
+
        echo -n 'Full name of the new user (without quotes, can have spaces):'
 +
        read full
 +
done
#The email address.  
#The email address.  
-
echo 'email address'
+
while [ -z $email ] ;do
-
read email
+
echo -n 'Email address of the new user:'
 +
read email
 +
done
 +
 
#The admin attribute 1 for admin or 0 for no admin role. 2 can also be given this will make it a system admin.
#The admin attribute 1 for admin or 0 for no admin role. 2 can also be given this will make it a system admin.
-
echo 'administrator 1 for yes 0 for no'
+
while [ -z $admin ] ;do
-
read admin
+
echo 'Should the user have administrator rights?'
-
admin="${admin:-0}"
+
echo 'Enter 1 for yes, 0 for no (The default is no):'
-
if [ $admin == "0" -o $admin == "0" ]; then
+
read admin
-
  echo -n "User not admin "
+
admin="${admin:-0}"
-
fi
+
done
#The non-active attribute for non-active users (resources)  
#The non-active attribute for non-active users (resources)  
-
echo 'non active 1 for yes 0 for no'
+
while [-z $non ] ;do
-
read non
+
echo 'Should the non active bit be set for this user? This is common for resources.'
 +
echo 'Enter 1 for yes, 0 for no (The default is no):'
 +
read non
 +
non="${non:-0}"
 +
done
#The zarafa-admin command to create the user with the input given by the user.
#The zarafa-admin command to create the user with the input given by the user.
zarafa-admin -c "$username" -p "$password" -f "$full" -e "$email" -a "$admin" -n "'$non"
zarafa-admin -c "$username" -p "$password" -f "$full" -e "$email" -a "$admin" -n "'$non"
 +
 +
# Here we add the resource attributes if you want to.
 +
if [ $non == "1" -o $non == "1" ]; then
 +
  echo  'This user is non active. Please set the resource attributes as well.'
 +
  echo  'Would you like to use this resource as a bookable room? Yes/No:'
 +
  read accept
 +
 +
# If the resource is set to auto accept you might want to set these options aswell.
 +
  if [ $accept == "yes" ]; then
 +
    echo -n 'Would you like to make the resource decline recurring appointments? Yes/No:'
 +
    read recurring
 +
    echo -n 'Would you like to make the resource decline conflicting appointments? Yes/No:'
 +
    read conflict
 +
    zarafa-admin -u "$username" --mr-accept "$accept" --mr-decline-conflict "$conflict" --mr-decline-recurring "$recurring"
 +
 +
  fi
 +
  echo "done"
 +
 +
fi
 +
 +
 +
#The details of the user will now be displayed:
 +
echo 'User created with the following details:'
 +
zarafa-admin --details "$username"
exit;
exit;
</pre>
</pre>

Revision as of 15:05, 7 January 2011

The Zarafa create user script.

This is a script that can be used to create users in a more friendly way for people who are new to Linux.

The script will ask what values you want to give to a user, like: User name, Password, full name, email address, administrator or not and if the user is non-active or active.

Also when a non-active user is created the resource attributes will be asked. (auto accept meeting request and declining recurring and/or conflicting).

To use the script run it as root. (Zarafa-server needs to be running)

Feel free to improve the script.


The script:

#!/usr/bin/env bash

# Script to create a user in Zarafa with the DB user plugin.
# Version (date / time): 20110107-13:00
#
# WARNING: DO NOT use this script when using the UNIX, LDAP or
# Active Directory plugin!
echo 'This script will help you creating a new Zarafa user.'
echo 'DISCLAIMER: This script is only suitable for use with the DB plugin.'
echo 'Creating a new Zarafa user. Please enter the details of the user.'

# Check if the user is root (required to run the zarafa-admin tool).
if [ $USER != 'root' ]
then
echo
echo "You need root privileges to run this script. Exiting."
exit 0
fi

#The user name. Input needed is the user name.
echo
while [ -z $username ] ;do 
	echo -n 'User name of the new user:'
	read username
done

#The password.
while [ -z $password ] ;do
       	echo -n 'Password (will not be visible on input):'
	read -s password
	echo ' '
done

#The full name. No " "  needed for full names with spaces
while [ -z $full ] ;do
        echo -n 'Full name of the new user (without quotes, can have spaces):'
        read full
done

#The email address. 
while [ -z $email ] ;do
	echo -n 'Email address of the new user:'
	read email
done


#The admin attribute 1 for admin or 0 for no admin role. 2 can also be given this will make it a system admin.
while [ -z $admin ] ;do
	echo 'Should the user have administrator rights?'
	echo 'Enter 1 for yes, 0 for no (The default is no):'
	read admin
	admin="${admin:-0}"
done

#The non-active attribute for non-active users (resources) 
while [-z $non ] ;do
	echo 'Should the non active bit be set for this user? This is common for resources.'
	echo 'Enter 1 for yes, 0 for no (The default is no):'
	read non
	non="${non:-0}"
done

#The zarafa-admin command to create the user with the input given by the user.
zarafa-admin -c "$username" -p "$password" -f "$full" -e "$email" -a "$admin" -n "'$non"

# Here we add the resource attributes if you want to.
if [ $non == "1" -o $non == "1" ]; then
  echo  'This user is non active. Please set the resource attributes as well.'
  echo  'Would you like to use this resource as a bookable room? Yes/No:'
  read accept

# If the resource is set to auto accept you might want to set these options aswell.
   if [ $accept == "yes" ]; then
     echo -n 'Would you like to make the resource decline recurring appointments? Yes/No:'
     read recurring
     echo -n 'Would you like to make the resource decline conflicting appointments? Yes/No:'
     read conflict
     zarafa-admin -u "$username" --mr-accept "$accept" --mr-decline-conflict "$conflict" --mr-decline-recurring "$recurring" 

  fi
  echo "done"

fi


#The details of the user will now be displayed:
echo 'User created with the following details:'
zarafa-admin --details "$username"

exit;
Personal tools