7source ${0%${script}}ulib.sh
9set_variable: DEBUG ARCHIVE_DEBUG 2
10set_variable VERSION "*"
13 usage "$script <path> <detector identifier> <run> <type> [version] <output file>"\
14 "\nUtility script to retrieve file from archive."\
15 "\nNote that extension from name of file in archive is taken."
19 6) set_variable VERSION $argv[5];&
20 5) set_variable DIR $argv[1];
23 set_variable TYPE $argv[4];
24 set_variable OUTPUT_FILE $argv[-1];;
25 *) fatal "Wrong number of arguments."
28if [[ ! -d $DIR ]]; then
29 fatal "Invalid path $argv[1]"
32if (( $ID == 0 )); then
33 fatal "Invalid detector identifier $argv[2]"
36if (( $RUN == 0 )); then
37 fatal "Invalid run $argv[3]"
47if [[ ! -d $DIR ]]; then
48 fatal "No archive $DIR"
51typeset -T BUFFER ARRAY /
55eval ls -1 $ID/$TYPE/_${VERSION}/\*/\*/\* 2> /dev/null | while read BUFFER; do
57 set_variable A_ID ${ARRAY[-6]}
58 set_variable A_TYPE ${ARRAY[-5]}
59 set_variable A_VERSION ${ARRAY[-4]#_}
60 let A_MINRUN=" ${ARRAY[-3]}"
61 let A_MAXRUN=" ${ARRAY[-2]}"
62 set_variable A_FILENAME ${ARRAY[-1]}
64 let A_COUNTER="${A_FILENAME:r}"
66 if (( $RUN >= $A_MINRUN && $RUN <= $A_MAXRUN )); then
67 if (( $A_COUNTER > $COUNTER )); then
68 let COUNTER="$A_COUNTER"
74if [[ -n $INPUT_FILE ]]; then
76 if [[ $(git rev-parse --is-inside-work-tree) == "true" ]]; then
78 git check-attr --all -- $INPUT_FILE | grep "filter: *lfs" >& /dev/null
80 if (( $? == 0 )); then
82 git lfs pull --exclude= --include $INPUT_FILE
84 if (( $? != 0 )); then
85 fatal "git lsf unavailable."
90 INPUT_FILE="$DIR/$INPUT_FILE"
95if [[ ! -f $INPUT_FILE ]]; then
96 fatal "No corresponding file found in archive $DIR"
99OUTPUT_FILE+=.${INPUT_FILE:e}
101if [[ -f $OUTPUT_FILE ]]; then
102 fatal "File $OUTPUT_FILE already exists."
105cp -p $INPUT_FILE $OUTPUT_FILE
107if (( $? == 0 )); then
108 notice "Stored archive:$INPUT_FILE to $OUTPUT_FILE"
110 fatal "File $INPUT_FILE not retrieved from archive."