]> arthur.barton.de Git - usertools.macosx.git/blob - userlist.macosx.sh
Add GNU General Public License text and pointers
[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 program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.
13 # See the GNU General Public License for more details.
14 #
15
16 RELEASE="2"
17
18 Usage() {
19         echo "$NAME (userlist.macosx.sh) release $RELEASE"
20         echo "Copyright (c)2008,2009 Barton IT-Consulting, Alex Barton (alex@barton-it.de)"
21         echo
22         echo "This is free software; see the source for copying conditions. There is NO"
23         echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
24         echo
25         echo "Usage: $0 [--all|-a] [--local|-l]"
26         echo
27         exit 1
28 }
29
30 while [ -n "$1" ]; do
31         case "$1" in
32         "--all"|"-a")
33                 ALL=1
34                 ;;
35         "--local"|"-l")
36                 LOCAL=1
37                 ;;
38         *)
39                 Usage
40                 exit 1
41         esac
42         shift
43 done
44
45 sw_vers -productName | grep -i "Server" >/dev/null 2>&1
46 if [ $? -eq 0 -a -z "$LOCAL" ]; then
47         # Mac OS X Server
48         OD=1
49 fi
50
51 if [ -n "$OD" ]; then
52         HOST="localhost"
53         USER_BASE="/LDAPv3/127.0.0.1/Users"
54         UID_MIN=1000
55 else
56         HOST="."
57         USER_BASE="/Users"
58         UID_MIN=500
59 fi
60
61 [ -n "$ALL" ] && UID_MIN=0
62
63 dscl "$HOST" -list "$USER_BASE" | while read x; do
64         declare -i id
65         id=`dscl "$HOST" -read "$USER_BASE/$x" UniqueID | cut -d: -f2`
66         if [ "$id" -gt $UID_MIN ]; then
67                 echo " $id: $x"
68         fi
69 done | sort -n
70
71 # -eof-