]> git.saurik.com Git - apple/xnu.git/blame_incremental - tools/tests/libMicro/od_account_create.sh
xnu-1699.22.73.tar.gz
[apple/xnu.git] / tools / tests / libMicro / od_account_create.sh
... / ...
CommitLineData
1#!/bin/bash
2
3
4function sighandler {
5 echo
6 echo "Interrupting account creation"
7 rm -f $TMPF
8 exit 1
9}
10
11trap sighandler INT TERM
12
13# Fixed parameters
14#
15NAME=`basename $0`
16COUNT=$1
17NODE=$2
18PREFIX="od_test_"
19GROUP_ID=1211 # A group everybody's in
20GROUP_ID2=1212 # A group nobody's in
21GROUP_NAME='od_test_group'
22UID_BASE=5000
23TMPF=/tmp/.${NAME}.$$
24
25usage () {
26 echo
27 echo "Usage: ${NAME} count nodename"
28 echo
29 echo " ie. ${NAME} 1000 /Local/Default"
30 echo
31 echo " will create users 1000 users (from '${PREFIX}1' to '${PREFIX}1000')"
32 echo " Default password is set to 'test'"
33 echo " User ID starts from 5000"
34 echo " Default group is '${GROUP_NAME}', Group ID 1211"
35 echo
36 echo "This tool assumes user 'diradmin' with password 'admin' for OD admin"
37 echo
38 exit 85 # WRONGARGS
39}
40
41if [ $# -ne 2 ]; then
42 usage
43fi
44
45# if local node we don't need credentials
46if [ $NODE != "/Local/Default" ]; then
47 OD_ADMIN="diradmin"
48 OD_PASS="admin"
49fi
50
51echo "Creating users ${PREFIX}1 to ${PREFIX}$COUNT"
52
53# check to see if od_test_group exist. if not, create one
54#
55result=`dscl $NODE -list Groups/${GROUP_NAME}1 2> /dev/null`
56if [ $? -ne 0 ]; then
57 echo "Group \"${GROUP_NAME}\" does not exist. Creating ${GROUP_NAME}"
58 if [ -n "$OD_ADMIN" ]; then
59 dseditgroup -q -o create -n $NODE -u $OD_ADMIN -P $OD_PASS -i ${GROUP_ID} ${GROUP_NAME}1
60 dseditgroup -q -o create -n $NODE -u $OD_ADMIN -P $OD_PASS -i ${GROUP_ID2} ${GROUP_NAME}2
61 else
62 dseditgroup -q -o create -n $NODE -i ${GROUP_ID} ${GROUP_NAME}1
63 dseditgroup -q -o create -n $NODE -i ${GROUP_ID2} ${GROUP_NAME}2
64 fi
65fi
66
67if [ $? -ne 0 ]; then
68 echo "Failed to create test_group"
69 exit 1
70fi
71
72# using dsimport is faster than using dscl
73i=1
74uid=$UID_BASE
75echo "Writing a temporary import file ..."
76while [ $i -le $COUNT ]
77do
78 result=`dscl $NODE -list Users/${PREFIX}${i} 2> /dev/null`
79 if [ $? -ne 0 ]; then
80 # Uses standard template
81 # RecordName:Password:UniqueID:PrimaryGroupID:DistinguishedName:NFSHomeDirectory:UserShell
82 echo "${PREFIX}${i}:test:${uid}:1211:${PREFIX}${i}:/Users/${PREFIX}${i}:/bin/bash" >> $TMPF
83 printf "\r${PREFIX}${i} / ${COUNT}"
84 else
85 echo "account $PREFIX$i already exist. skipping"
86 fi
87 i=`expr $i + 1`
88 uid=`expr $uid + 1`
89done
90echo
91
92# Now do the real work
93#
94if [[ -f $TMPF ]]; then
95 echo "Running dsimport to create users. Please be patient. This takes a while ..."
96 # assume if admin is provided that slapconfig exists
97 if [ -n "$OD_ADMIN" ]; then
98 if [[ -x "/usr/sbin/slapconfig" ]]; then
99 /usr/sbin/slapconfig -setfullsyncmode no
100 sleep 2
101 fi
102 /usr/bin/time dsimport $TMPF $NODE I --username $OD_ADMIN --password $OD_PASS --template StandardUser
103 sleep 2
104 if [[ -x "/usr/sbin/slapconfig" ]]; then
105 /usr/sbin/slapconfig -setfullsyncmode yes
106 fi
107 else
108 /usr/bin/time dsimport $TMPF $NODE I --template StandardUser
109 sleep 2
110 fi
111
112 # and now delete the temp file
113 #
114 rm -f $TMPF
115else
116 echo "Nothing done. All users already exist"
117fi
118
119echo Create a SACL group for libMicro
120# Create a sample SACL group
121dseditgroup -q -o create -r "libMicro ACL" com.apple.access_libMicro
122i=1
123while [ $i -le $COUNT ]; do
124 dseditgroup -q -o edit -a ${PREFIX}${i} -t user com.apple.access_libMicro
125 i=`expr $i + 1`
126done
127
128echo 'Finished'
129