-
Notifications
You must be signed in to change notification settings - Fork 16
/
getUserGroups.sh
70 lines (62 loc) · 1.55 KB
/
getUserGroups.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
###
### Script for getting Alfresco Groups of a given user via REST API /service/api/people
###
# Usage functions
usage() { echo "Usage: $0 [-f] [-a user]" 1>&2; exit 1; }
# Command line options
while getopts "fa:u:p:he:s:" o; do
case "${o}" in
f)
FULL=1
;;
u)
MYUSER=${OPTARG}
;;
p)
MYPASS=${OPTARG}
;;
e)
ALFURL=${OPTARG}
;;
s)
SITE=${OPTARG}
;;
a)
AUSER=${OPTARG}
;;
\?)
echo "Invalid Option: -$OPTARG" 1>&2
exit 1
;;
h)
usage
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
# Exports ALFALFURL,MYUSER,MYPASS
source ./exportENVARS.sh
# Needs at least ALFURL as parameter
if [ -z "${ALFURL}" ] || [ -z "${MYUSER}" ] || [ -z "${MYPASS}" ]; then
usage
fi
# Needs at least AUSER as parameter
if [ -z "${AUSER}" ]; then
usage
fi
# Default parameters
#ALFURL=${ALFURL:-http://localhost:8080/alfresco}
#MYUSER=${MYUSER:-admin}
#MYPASS=${MYPASS:-admin}
FULL=${FULL:-0}
# Full/Brief report
# PS: Needs jq and jsonv
if [ "${FULL}" == "1" ]; then
curl -s -u $MYUSER:$MYPASS "$ALFURL/service/api/people/$AUSER?groups=true" | jq '.groups[] | "\(.itemName),\(.displayName)"' | sed -e 's#\"##g' | sed -e 's#\\##g'
else
curl -s -u $MYUSER:$MYPASS "$ALFURL/service/api/people/$AUSER?groups=true" | jq '.groups[] .itemName' | sed -e 's#\"##g' | sed -e 's#\\##g'
fi