]> Creatis software - clitk.git/blob - grid/common.sh
bb0b05b7f64771cabcf3042db11f4d180d5d90b0
[clitk.git] / grid / common.sh
1
2 set -u
3
4 # print error message and exit immediately
5 programname="$(basename ${0})"
6 function error {
7 echo "${programname} **ERROR** $1"
8 exit 1
9 }
10
11 # ensure a valid proxy is present for at least one hour
12 # if no proxy is found, try to create a new one
13 # return 0 if a valid proxy is found or created
14 # else return voms-proxy-init error code
15 function ensure_proxy {
16 voms-proxy-info --exists -valid 1:0 > /dev/null && return 0 
17 voms-proxy-init --voms biomed -valid 24:00 || exit 1
18 }
19
20 # print prompt to ensure that the user want to continue further
21 # the user has to answer with 'y' to continue
22 function check_user {
23 prompt="${1:-is that correct?}"
24 read -p "${prompt} [y/n] " answer
25 test "${answer}" == "y" && return 0
26 test "${answer}" == "n" && return 1
27 check_user "${prompt}"
28 }
29
30 # checks if the lfn file exists
31 function file_exists {
32 lfnfile="${1:?"provide lfn to file"}"
33 lfc-ls ${lfnfile} 2>&1 > /dev/null
34 }
35
36 # upload file to grid storage element
37 # source can be a relative or an absolute path to the source file 
38 # dest must be the lfn to the target **file** (not the directory) 
39 # if dest already exists, it prompts the user for overwritting
40 function upload_file {
41 sourcefile=${1:?"provide source file"}
42 destlfn=${2:?"provide destination file lfn"}
43 sourcefile="$(readlink -f "${sourcefile}")" # convert to absolute path
44 test -f "${sourcefile}" || error "can't find ${sourcefile}"
45 echo "uploading ${sourcefile} to ${destlfn}"
46 if file_exists "${destlfn}"; then
47         check_user "${destlfn} already exists. overwrite it?" || exit 2
48         lcg-del -a "lfn:${destlfn}"
49 fi
50 echo "lets roll"
51 lcg-cr -v -d ccsrm02.in2p3.fr -l "lfn:${destlfn}" "file:${sourcefile}" 
52 }
53
54
55 # common path used
56 lfnbase="/grid/biomed/creatis/fgate/"
57 lfnrelease="${lfnbase}releases/"
58 lfnworkflow="${lfnbase}workflow/"
59 lfngasw="${lfnbase}gasw/"
60 lfnscript="${lfnbase}bin/"
61
62 # define the prefix for uploaded file
63 # default to local machine username
64 prefix="${USER:?"USER must be set"}_"