-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosgconnect_show_projects
executable file
·54 lines (48 loc) · 1.77 KB
/
osgconnect_show_projects
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
#!/bin/sh
#Marco Mambelli 130820 [email protected]
# Project names translation as of 9/17/13
# all Projects have corresponding UNIX groups starting with "@"
function help_msg {
cat >&2 << EOF
$0 [ -h | -u USER ] [PROJECT]
Prints the projects membership for the user if no PROJECT is provided (exit code 0)
If PROJECT is provided returns 0 if the user is member, 1 otherwise
-u USER set the user name (the user running the script by default)
-q quiet (prints only the projects list when no project is provided)
-h print this help message
EOF
}
me=`whoami`
while getopts hqu: option
do
case "${option}"
in
"h") help_msg; exit 2;;
"u") me=${OPTARG};;
"q") QUIET="true";;
*) help_msg; exit 2;;
esac
done
shift $((OPTIND-1))
# Check for project membership
if [ ! -z $1 ]; then
PROJECT=$1
# return membership
#tmp_group=`echo "_$PROJECT" | sed -e 's/^_con-/@/'`
tmp_group=`echo "@$PROJECT"`
echo ,$(getent group $tmp_group | cut -d: -f4), | grep ",$me," 2>&1 > /dev/null
RETV=$?
if [ -z $QUIET ]; then
[ $RETV -eq 0 ] && echo "User $me belongs to project $PROJECT" || echo "User $me does not belong to project $PROJECT"
fi
exit $RETV
fi
# Return project list
if [ -z $QUIET ]; then
echo "Based on username ($me), here is a list of projects you might have"
echo "access to:"
fi
# Using "getent group" instead of "ypcat group" to include also local groups (e.g. OSG-Staff)
echo "$(getent group | tr : , | sed -e 's/$/,/' | grep ,$me, | cut -d, -f1 | grep ^[@] | sed -e 's/^@//' | sort)"
#mygroups=",$(ypcat group | tr : , | sed -e 's/$/,/' | grep ,$me, | cut -d, -f1 | tr \n ,)"
#echo "$(echo $mygroups| sed -e 's/,train,/,con-train,/' | sed -e 's/,atlas,/,con-atlas,/' | sed -e 's/,staff,/,con-staff,/' | sed -e 's/,swift,/,con-swift,/' )"