od_account_create.sh [plain text]
#!/bin/bash
function sighandler {
echo
echo "Interrupting account creation"
rm -f $TMPF
exit 1
}
trap sighandler INT TERM
NAME=`basename $0`
COUNT=$1
NODE=$2
PREFIX="od_test_"
GROUP_ID=1211 GROUP_ID2=1212 GROUP_NAME='od_test_group'
UID_BASE=5000
TMPF=/tmp/.${NAME}.$$
usage () {
echo
echo "Usage: ${NAME} count nodename"
echo
echo " ie. ${NAME} 1000 /Local/Default"
echo
echo " will create users 1000 users (from '${PREFIX}1' to '${PREFIX}1000')"
echo " Default password is set to 'test'"
echo " User ID starts from 5000"
echo " Default group is '${GROUP_NAME}', Group ID 1211"
echo
echo "This tool assumes user 'diradmin' with password 'admin' for OD admin"
echo
exit 85 }
if [ $ usage
fi
if [ $NODE != "/Local/Default" ]; then
OD_ADMIN="diradmin"
OD_PASS="admin"
fi
echo "Creating users ${PREFIX}1 to ${PREFIX}$COUNT"
result=`dscl $NODE -list Groups/${GROUP_NAME}1 2> /dev/null`
if [ $? -ne 0 ]; then
echo "Group \"${GROUP_NAME}\" does not exist. Creating ${GROUP_NAME}"
if [ -n "$OD_ADMIN" ]; then
dseditgroup -q -o create -n $NODE -u $OD_ADMIN -P $OD_PASS -i ${GROUP_ID} ${GROUP_NAME}1
dseditgroup -q -o create -n $NODE -u $OD_ADMIN -P $OD_PASS -i ${GROUP_ID2} ${GROUP_NAME}2
else
dseditgroup -q -o create -n $NODE -i ${GROUP_ID} ${GROUP_NAME}1
dseditgroup -q -o create -n $NODE -i ${GROUP_ID2} ${GROUP_NAME}2
fi
fi
if [ $? -ne 0 ]; then
echo "Failed to create test_group"
exit 1
fi
i=1
uid=$UID_BASE
echo "Writing a temporary import file ..."
while [ $i -le $COUNT ]
do
result=`dscl $NODE -list Users/${PREFIX}${i} 2> /dev/null`
if [ $? -ne 0 ]; then
echo "${PREFIX}${i}:test:${uid}:1211:${PREFIX}${i}:/Users/${PREFIX}${i}:/bin/bash" >> $TMPF
printf "\r${PREFIX}${i} / ${COUNT}"
else
echo "account $PREFIX$i already exist. skipping"
fi
i=`expr $i + 1`
uid=`expr $uid + 1`
done
echo
if [[ -f $TMPF ]]; then
echo "Running dsimport to create users. Please be patient. This takes a while ..."
if [ -n "$OD_ADMIN" ]; then
if [[ -x "/usr/sbin/slapconfig" ]]; then
/usr/sbin/slapconfig -setfullsyncmode no
sleep 2
fi
/usr/bin/time dsimport $TMPF $NODE I --username $OD_ADMIN --password $OD_PASS --template StandardUser
sleep 2
if [[ -x "/usr/sbin/slapconfig" ]]; then
/usr/sbin/slapconfig -setfullsyncmode yes
fi
else
/usr/bin/time dsimport $TMPF $NODE I --template StandardUser
sleep 2
fi
rm -f $TMPF
else
echo "Nothing done. All users already exist"
fi
echo Create a SACL group for libMicro
dseditgroup -q -o create -r "libMicro ACL" com.apple.access_libMicro
i=1
while [ $i -le $COUNT ]; do
dseditgroup -q -o edit -a ${PREFIX}${i} -t user com.apple.access_libMicro
i=`expr $i + 1`
done
echo 'Finished'