Commit | Line | Data |
---|---|---|
6d2010ae A |
1 | #!/bin/bash |
2 | ||
3 | function sighandler { | |
4 | echo | |
5 | echo "Interrupting account creation" | |
6 | rm -f $TMPF | |
7 | exit 2 | |
8 | } | |
9 | ||
10 | trap sighandler INT TERM | |
11 | ||
12 | # Fixed parameters | |
13 | # | |
14 | NAME=`basename $0` | |
15 | COUNT=$1 | |
16 | PREFIX="od_test_" | |
17 | GROUP_NAME='od_test_group' | |
18 | TMPF=/tmp/.${NAME}.$$ | |
19 | NODE=$2 | |
20 | ||
21 | usage () { | |
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 | ||
35 | if [ $# -ne 2 ]; then | |
36 | usage | |
37 | fi | |
38 | ||
3e170ce0 | 39 | # we don't need credentials if its a local node |
6d2010ae A |
40 | if [ $NODE != "/Local/Default" ]; then |
41 | OD_ADMIN="diradmin" | |
42 | OD_PASS="admin" | |
43 | fi | |
44 | ||
45 | echo "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 | # | |
50 | i=1 | |
51 | echo "Writing a temporary script ..." | |
52 | if [ -n "$OD_ADMIN" ]; then | |
53 | echo "auth $OD_ADMIN $OD_PASS" >> $TMPF | |
54 | fi | |
55 | ||
56 | while [ $i -le $COUNT ] | |
57 | do | |
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` | |
64 | done | |
65 | echo | |
66 | ||
67 | echo "Deleting temporary test groups" | |
68 | if [ -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` | |
71 | else | |
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` | |
74 | fi | |
75 | ||
76 | result=`dseditgroup -q -o delete com.apple.access_libMicro 2>&1 /dev/null` | |
77 | ||
78 | # Now do the real work | |
79 | # | |
80 | if [[ -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 | |
91 | fi | |
92 | ||
93 | # and now delete the temp file | |
94 | # | |
95 | rm -f $TMPF | |
96 | ||
97 | echo 'Finished' | |
98 |