1 |
#! /bin/sh |
2 |
# |
3 |
# @(#)$Id$ |
4 |
# |
5 |
# (C) Copyright 2009 Nikhef, National Institute for Subatomic Physics |
6 |
# David Groep, Grid PDP group |
7 |
# |
8 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
9 |
# not use this file except in compliance with the License. You may obtain |
10 |
# a copy of the License at |
11 |
# http://www.apache.org/licenses/LICENSE-2.0 |
12 |
# Unless required by applicable law or agreed to in writing, software |
13 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 |
# See the License for the specific language governing permissions and |
16 |
# limitations under the License. |
17 |
# |
18 |
# Purpose: |
19 |
# Set the VO_xxx_CACHE_DIR variable when appropriate, based on a list of |
20 |
# possible base directories for such a cache. The script will accept any |
21 |
# incoming VONAME definition (such as set by the globus Job Manager patch) |
22 |
# but failing that will try to determine the VO based on the VOMS proxy. |
23 |
# |
24 |
# Configuration: will read /etc/sysconfig/vocachedir |
25 |
# Set CACHEBASES to a list of directory paths to which the voname (in |
26 |
# lower case) will be appended to name the actual cache directory. Its |
27 |
# permissions MUST be at least 01755 (i.e. the directory MUST be sticky) |
28 |
# and it MUST be owned by root |
29 |
# |
30 |
# Note: the script will NOT do cleanup of this directory, use tmpwatch(8) |
31 |
# for that. |
32 |
|
33 |
cacheverbose=${cacheverbose:-0} |
34 |
vomsproxyinfo=/opt/glite/bin/voms-proxy-info |
35 |
CACHEBASES="/var/cache/grid /tmp/gridcache" |
36 |
|
37 |
if test -f /etc/sysconfig/vocachedir |
38 |
then |
39 |
. /etc/sysconfig/vocachedir |
40 |
fi |
41 |
|
42 |
voclog() { |
43 |
if test "$cacheverbose" -ne 0 |
44 |
then |
45 |
echo "$@" >&2 |
46 |
fi |
47 |
} |
48 |
|
49 |
if test -z "$VONAME" -a -n "$X509_USER_PROXY" |
50 |
then |
51 |
if test -x $vomsproxyinfo |
52 |
then |
53 |
voname=$($vomsproxyinfo -file "$X509_USER_PROXY" -vo 2>/dev/null) |
54 |
case "$voname" in |
55 |
[a-zA-Z][-a-zA-Z.]* ) |
56 |
VONAME="$voname" |
57 |
export VONAME |
58 |
if test -n "$ISCSHELL" |
59 |
then |
60 |
echo "setenv VONAME \"$voname\"" |
61 |
fi |
62 |
;; |
63 |
* ) |
64 |
unset voname |
65 |
;; |
66 |
esac |
67 |
fi |
68 |
fi |
69 |
|
70 |
# utility function to set it (allows local vars) |
71 |
setvocachedir() { |
72 |
local voucalias volcalias dirperm dir |
73 |
|
74 |
voucalias=$(echo "$VONAME" | tr a-z A-Z | sed -e 's/[^a-zA-Z0-9]/_/g') |
75 |
volcalias=$(echo "$VONAME" | tr A-Z a-z | sed -e 's/[^a-zA-Z0-9]/_/g') |
76 |
for dir in $CACHEBASES |
77 |
do |
78 |
voclog "Testing availability of cache base $dir" |
79 |
if test -d "$dir/$volcalias" |
80 |
then |
81 |
dirperm=$(stat -c %a "$dir/$volcalias") |
82 |
dirowner=$(stat -c %u "$dir/$volcalias") |
83 |
voclog "Testing $dir/$volcalias (perm=$dirperm,uid=$dirowner)" |
84 |
if test "$dirperm" -lt 1755 |
85 |
then |
86 |
voclog Cache $dir/$volcalias exists but permissions $dirperm too lax |
87 |
voclog Declining to set VO_${voucalias}_CACHE_DIR |
88 |
return 1 |
89 |
fi |
90 |
if test "$dirowner" -ne 0 |
91 |
then |
92 |
voclog Cache $dir/$volcalias exists but owner is not root but $dirowner |
93 |
voclog Declining to set VO_${voucalias}_CACHE_DIR |
94 |
return 1 |
95 |
fi |
96 |
eval VO_${voucalias}_CACHE_DIR="$dir/$volcalias" |
97 |
eval export VO_${voucalias}_CACHE_DIR |
98 |
if test -n "$ISCSHELL" |
99 |
then |
100 |
echo "setenv VO_${voucalias}_CACHE_DIR \"$dir/$volcalias\"" |
101 |
fi |
102 |
break |
103 |
fi |
104 |
done |
105 |
return 0; |
106 |
} |
107 |
|
108 |
# we have figured out the VO name if it is to be found at all |
109 |
# only continue if the VO is set, as we do not offer a generic cache |
110 |
if test -n "$VONAME" |
111 |
then |
112 |
setvocachedir |
113 |
fi |
114 |
|
115 |
unset setvocachedir |
116 |
unset voclog |
117 |
unset voname |