]> arthur.barton.de Git - usertools.macosx.git/blob - userlist.macosx.sh
rename: listusers.sh -> userlist.macosx.sh
[usertools.macosx.git] / userlist.macosx.sh
1 #!/bin/bash
2
3 while [ -n "$1" ]; do
4         case "$1" in
5         "--all"|"-a")
6                 ALL=1
7                 ;;
8         "--local"|"-l")
9                 LOCAL=1
10                 ;;
11         *)
12                 echo "Usage: $0 [--local|-l]"
13                 exit 1
14         esac
15         shift
16 done
17
18 sw_vers -productName | grep -i "Server" >/dev/null 2>&1
19 if [ $? -eq 0 -a -z "$LOCAL" ]; then
20         # Mac OS X Server
21         OD=1
22 fi
23
24 if [ -n "$OD" ]; then
25         HOST="localhost"
26         USER_BASE="/LDAPv3/127.0.0.1/Users"
27         UID_MIN=1000
28 else
29         HOST="."
30         USER_BASE="/Users"
31         UID_MIN=500
32 fi
33
34 [ -n "$ALL" ] && UID_MIN=0
35
36 dscl "$HOST" -list "$USER_BASE" | while read x; do
37         declare -i id
38         id=`dscl "$HOST" -read "$USER_BASE/$x" UniqueID | cut -d: -f2`
39         if [ "$id" -gt $UID_MIN ]; then
40                 echo " $id: $x"
41         fi
42 done | sort -n
43
44 # -eof-