Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
getFile.sh
Go to the documentation of this file.
1#!/usr/bin/env zsh
2#
3# \author mdejong
4#
5script=${0##*/}
6
7source ${0%${script}}ulib.sh
8
9set_variable: DEBUG ARCHIVE_DEBUG 2
10set_variable VERSION "*"
11
12if do_usage $*; then
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."
16fi
17
18case $# in
19 6) set_variable VERSION $argv[5];&
20 5) set_variable DIR $argv[1];
21 let ID=" $argv[2]";
22 let RUN=" $argv[3]";
23 set_variable TYPE $argv[4];
24 set_variable OUTPUT_FILE $argv[-1];;
25 *) fatal "Wrong number of arguments."
26esac
27
28if [[ ! -d $DIR ]]; then
29 fatal "Invalid path $argv[1]"
30fi
31
32if (( $ID == 0 )); then
33 fatal "Invalid detector identifier $argv[2]"
34fi
35
36if (( $RUN == 0 )); then
37 fatal "Invalid run $argv[3]"
38fi
39
40setopt extendedglob
41
42typeset -Z8 ID
43
44let COUNTER="0"
45INPUT_FILE=""
46
47if [[ ! -d $DIR ]]; then
48 fatal "No archive $DIR"
49fi
50
51typeset -T BUFFER ARRAY /
52
53pushd $DIR
54
55eval ls -1 $ID/$TYPE/_${VERSION}/\*/\*/\* 2> /dev/null | while read BUFFER; do
56
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]}
63
64 let A_COUNTER="${A_FILENAME:r}"
65
66 if (( $RUN >= $A_MINRUN && $RUN <= $A_MAXRUN )); then
67 if (( $A_COUNTER > $COUNTER )); then
68 let COUNTER="$A_COUNTER"
69 INPUT_FILE=$BUFFER
70 fi
71 fi
72done
73
74if [[ -n $INPUT_FILE ]]; then
75
76 if [[ $(git rev-parse --is-inside-work-tree) == "true" ]]; then
77
78 git check-attr --all -- $INPUT_FILE | grep "filter: *lfs" >& /dev/null
79
80 if (( $? == 0 )); then
81
82 git lfs pull --exclude= --include $INPUT_FILE
83
84 if (( $? != 0 )); then
85 fatal "git lsf unavailable."
86 fi
87 fi
88 fi
89
90 INPUT_FILE="$DIR/$INPUT_FILE"
91fi
92
93popd
94
95if [[ ! -f $INPUT_FILE ]]; then
96 fatal "No corresponding file found in archive $DIR"
97fi
98
99OUTPUT_FILE+=.${INPUT_FILE:e}
100
101if [[ -f $OUTPUT_FILE ]]; then
102 fatal "File $OUTPUT_FILE already exists."
103fi
104
105cp -p $INPUT_FILE $OUTPUT_FILE
106
107if (( $? == 0 )); then
108 notice "Stored archive:$INPUT_FILE to $OUTPUT_FILE"
109else
110 fatal "File $INPUT_FILE not retrieved from archive."
111fi
112
113