]> arthur.barton.de Git - usertools.macosx.git/blob - userlist.macosx.sh
1ed60302c00e010d5278b4b8fd34185fa92135e9
[usertools.macosx.git] / userlist.macosx.sh
1 #!/bin/bash
2 #
3 # listusers.sh
4 # Copyright (c)2008,2009 Barton IT-Consulting, Alexander Barton
5 #
6 # This is free software; see the source for copying conditions. There is NO
7 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 #
9
10 RELEASE="2"
11
12 Usage() {
13         echo "$NAME (userlist.macosx.sh) release $RELEASE"
14         echo "Copyright (c)2008,2009 Barton IT-Consulting, Alex Barton (alex@barton-it.de)"
15         echo
16         echo "This is free software; see the source for copying conditions. There is NO"
17         echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
18         echo
19         echo "Usage: $0 [--all|-a] [--local|-l]"
20         echo
21         exit 1
22 }
23
24 while [ -n "$1" ]; do
25         case "$1" in
26         "--all"|"-a")
27                 ALL=1
28                 ;;
29         "--local"|"-l")
30                 LOCAL=1
31                 ;;
32         *)
33                 Usage
34                 exit 1
35         esac
36         shift
37 done
38
39 sw_vers -productName | grep -i "Server" >/dev/null 2>&1
40 if [ $? -eq 0 -a -z "$LOCAL" ]; then
41         # Mac OS X Server
42         OD=1
43 fi
44
45 if [ -n "$OD" ]; then
46         HOST="localhost"
47         USER_BASE="/LDAPv3/127.0.0.1/Users"
48         UID_MIN=1000
49 else
50         HOST="."
51         USER_BASE="/Users"
52         UID_MIN=500
53 fi
54
55 [ -n "$ALL" ] && UID_MIN=0
56
57 dscl "$HOST" -list "$USER_BASE" | while read x; do
58         declare -i id
59         id=`dscl "$HOST" -read "$USER_BASE/$x" UniqueID | cut -d: -f2`
60         if [ "$id" -gt $UID_MIN ]; then
61                 echo " $id: $x"
62         fi
63 done | sort -n
64
65 # -eof-