Created
January 30, 2020 21:49
-
-
Save gordyt/298be65fa4a9a46841b45653ce0e95e5 to your computer and use it in GitHub Desktop.
Easy way to provision a lot of users in Zimbra-X. Run with -h option for help.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
prefix="test" | |
domain="zmc.com" | |
ilen=1 | |
pw=test123 | |
function usage { | |
echo "usage: $0 -p <prefix> -d <domain> -w <password> [-z] <num-users>" | |
echo "defaults:" | |
echo "- prefix=$prefix" | |
echo "- domain=$domain" | |
echo "- password=$pw" | |
echo "" | |
echo "If you include -z option, will zero-pad the user index so all are the same length." | |
echo "For example, if you ask for 100 users to be created, and you specify the -z option," | |
echo "then the email addresses will look like this: ${prefix}001@${domain} - ${prefix}100@${domain}." | |
echo "Without the -z option they will look like this: ${prefix}1@${domain} - ${prefix}100@${domain}." | |
exit 1 | |
} | |
pad_users=false | |
while getopts ":w:p:d:zh" opt; do | |
case ${opt} in | |
p ) | |
prefix=$OPTARG | |
;; | |
d ) | |
domain=$OPTARG | |
;; | |
z ) | |
pad_users=true | |
;; | |
w ) | |
pw=$OPTARG | |
;; | |
h ) | |
usage | |
;; | |
\? ) | |
echo "Invalid option: $OPTARG" 1>&2 | |
usage | |
;; | |
: ) | |
echo "Invalid option: $OPTARG requires an argument" 1>&2 | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND -1)) | |
num_users="$1" | |
if [ -z "${num_users}" ]; then | |
echo "must specify number of users" | |
usage | |
fi | |
echo "creating $num_users users with prefix=$prefix, domain=$domain, pad_users=$pad_users, password=$pw" | |
if [ $pad_users == true ]; then | |
ilen=$(expr length $num_users) | |
fi | |
i=1 | |
while [ $i -le $num_users ]; do | |
ii=$(printf "%0${ilen}d" $i) | |
u="${prefix}$ii@${domain}" | |
echo "creating user $u with password $pw" | |
kubectl exec -it zmc-ldap-0 -- sudo -i -u zimbra zmprov ca "$u" "$pw" | |
i=$(expr $i + 1) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment