xnu-4570.20.62.tar.gz
[apple/xnu.git] / tools / tests / libMicro / od_account_delete.sh
CommitLineData
6d2010ae
A
1#!/bin/bash
2
3function sighandler {
4 echo
5 echo "Interrupting account creation"
6 rm -f $TMPF
7 exit 2
8}
9
10trap sighandler INT TERM
11
12# Fixed parameters
13#
14NAME=`basename $0`
15COUNT=$1
16PREFIX="od_test_"
17GROUP_NAME='od_test_group'
18TMPF=/tmp/.${NAME}.$$
19NODE=$2
20
21usage () {
22 echo
23 echo "Usage: ${NAME} count nodename"
24 echo
25 echo " ie. ${NAME} 1000 /Local/Default"
26 echo
27 echo " will delete ${GROUPNAME} and 1000 users "
28 echo " from '${PREFIX}1' to '${PREFIX}1000'"
29 echo
30 echo "This tool assumes user 'diradmin' with password 'admin' for OD admin"
31 echo "when talking to anything other than /Local/Default"
32 exit 85 # WRONGARGS
33}
34
35if [ $# -ne 2 ]; then
36 usage
37fi
38
3e170ce0 39# we don't need credentials if its a local node
6d2010ae
A
40if [ $NODE != "/Local/Default" ]; then
41 OD_ADMIN="diradmin"
42 OD_PASS="admin"
43fi
44
45echo "Deleting users ${PREFIX}1 to ${PREFIX}$COUNT"
46
47# Using a script file and feed it into dscl is much faster than
48# calling dscl everytime.
49#
50i=1
51echo "Writing a temporary script ..."
52if [ -n "$OD_ADMIN" ]; then
53 echo "auth $OD_ADMIN $OD_PASS" >> $TMPF
54fi
55
56while [ $i -le $COUNT ]
57do
58 result=`dscl $NODE -list Users/${PREFIX}${i} 2> /dev/null`
59 if [ $? -eq 0 ]; then
60 echo "delete Users/${PREFIX}${i}" >> $TMPF
61 printf "\r${PREFIX}${i} / ${COUNT}"
62 fi
63 i=`expr $i + 1`
64done
65echo
66
67echo "Deleting temporary test groups"
68if [ -n "$OD_ADMIN" ]; then
69 result=`dseditgroup -q -o delete -n $NODE -u $OD_ADMIN -P $OD_PASS ${GROUP_NAME}1 2>&1 /dev/null`
70 result=`dseditgroup -q -o delete -n $NODE -u $OD_ADMIN -P $OD_PASS ${GROUP_NAME}2 2>&1 /dev/null`
71else
72 result=`dseditgroup -q -o delete -n $NODE ${GROUP_NAME}1 2>&1 /dev/null`
73 result=`dseditgroup -q -o delete -n $NODE ${GROUP_NAME}2 2>&1 /dev/null`
74fi
75
76result=`dseditgroup -q -o delete com.apple.access_libMicro 2>&1 /dev/null`
77
78# Now do the real work
79#
80if [[ -f $TMPF ]]; then
81 echo "Running dscl to delete users. Please be patient. This takes a while ..."
82 if [[ -x /usr/sbin/slapconfig ]]; then
83 /usr/sbin/slapconfig -setfullsyncmode no
84 fi
85
86 /usr/bin/time dscl ${NODE} < $TMPF
87
88 if [[ -x /usr/sbin/slapconfig ]]; then
89 /usr/sbin/slapconfig -setfullsyncmode yes
90 fi
91fi
92
93# and now delete the temp file
94#
95rm -f $TMPF
96
97echo 'Finished'
98