4 # print error message and exit immediately
5 programname="$(basename ${0})"
7 echo "${programname} **ERROR** $1"
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
20 # print prompt to ensure that the user want to continue further
21 # the user has to answer with 'y' to continue
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}"
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
37 # upload file to grid storage element
38 # source can be a relative or an absolute path to the source file
39 # dest must be the lfn to the target **file** (not the directory)
40 # if dest already exists, it prompts the user for overwritting
41 function upload_file {
42 sourcefile=${1:?"provide source file"}
43 destlfn=${2:?"provide destination file lfn"}
44 sourcefile="$(readlink -f "${sourcefile}")" # convert to absolute path
45 test -f "${sourcefile}" || error "can't find ${sourcefile}"
46 echo "uploading ${sourcefile} to ${destlfn}"
47 if file_exists "${destlfn}"; then
48 check_user "${destlfn} already exists. overwrite it?" || return 2
49 lcg-del -a "lfn:${destlfn}" || error "lcg-del error"
53 local pending_ses=${SES}
54 local registered=false
55 while [ "x${pending_ses}" != "x" ]
57 #select a se from list
58 local S=`echo ${pending_ses} | awk '{print $1}'`
61 for i in `echo ${pending_ses}`
65 new_list="${new_list} ${i}"
68 pending_ses=${new_list}
69 local TEMP=`mktemp lcg-XXXXX`
70 if [ "${registered}" = "false" ]
72 echo -n "Registering release to ${S}..."
73 lcg-cr -v -d ${S} -l "lfn:${destlfn}" "file:${sourcefile}" &>${TEMP}
76 echo -e "\t [\033[31m FAILED \033[0m]"
80 echo -e "\t [\033[32m OK \033[0m]"
85 echo -n "Replicating release to ${S}..."
86 lcg-rep -v -d ${S} "lfn:${destlfn}" &>${TEMP}
89 echo -e "\t [\033[31m FAILED \033[0m]"
93 echo -e "\t [\033[32m OK \033[0m]"
102 lfnbase="/grid/biomed/creatis/fgate/"
103 lfnrelease="/grid/biomed/creatis/vip/data/groups/GateLab/releases/"
104 lfnworkflow="${lfnbase}workflow/"
105 lfngasw="${lfnbase}gasw/"
106 lfnscript="${lfnbase}bin/"
108 #list of SEs used for storage. Don't modify this list unless you know
109 # what you're doing. Replicating the release in a bad place (e.g. on a
110 # remote continent) can dramatically slow down the transfers
111 SES="ccsrm02.in2p3.fr sbgse1.in2p3.fr marsedpm.in2p3.fr"
113 # define the prefix for uploaded file
114 # default to local machine username
115 prefix="${USER:?"USER must be set"}_"