Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
getFile.sh
Go to the documentation of this file.
1 #!/bin/zsh
2 #
3 # \author mdejong
4 #
5 script=${0##*/}
6 
7 source ${0%${script}}ulib.sh
8 
9 set_variable: DEBUG ARCHIVE_DEBUG 2
10 set_variable VERSION "*"
11 
12 if 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."
16 fi
17 
18 case $# 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."
26 esac
27 
28 if [[ ! -d $DIR ]]; then
29  fatal "Invalid path $argv[1]"
30 fi
31 
32 if (( $ID == 0 )); then
33  fatal "Invalid detector identifier $argv[2]"
34 fi
35 
36 if (( $RUN == 0 )); then
37  fatal "Invalid run $argv[3]"
38 fi
39 
40 setopt extendedglob
41 
42 typeset -Z8 ID
43 
44 let COUNTER="0"
45 INPUT_FILE=""
46 
47 if [[ ! -d $DIR ]]; then
48  fatal "No archive $DIR"
49 fi
50 
51 typeset -T BUFFER ARRAY /
52 
53 pushd $DIR
54 
55 eval 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
72 done
73 
74 if [[ -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"
91 fi
92 
93 popd
94 
95 if [[ ! -f $INPUT_FILE ]]; then
96  fatal "No corresponding file found in archive $DIR"
97 fi
98 
99 OUTPUT_FILE+=.${INPUT_FILE:e}
100 
101 if [[ -f $OUTPUT_FILE ]]; then
102  fatal "File $OUTPUT_FILE already exists."
103 fi
104 
105 cp -p $INPUT_FILE $OUTPUT_FILE
106 
107 if (( $? == 0 )); then
108  notice "Stored archive:$INPUT_FILE to $OUTPUT_FILE"
109 else
110  fatal "File $INPUT_FILE not retrieved from archive."
111 fi
112 
113