Skip to content

Commit f3b8889

Browse files
c-dilkstongtongcao
authored andcommitted
fix(build): automatically choose data-retrieval option (#983)
1 parent 9cc0e7f commit f3b8889

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

build-coatjava.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ GENERAL OPTIONS
1616
1717
DATA RETRIEVAL OPTIONS
1818
How to retrieve magnetic field maps, neural network models, etc.;
19-
choose only one:
19+
choose only one, e.g., if the automated default choice fails:
2020
--lfs use Git Large File Storage (requires `git-lfs`)
2121
--cvmfs use CernVM-FS (requires `/cvfms`)
2222
--xrootd use XRootD (requires `xrootd`)
@@ -80,10 +80,34 @@ do
8080
esac
8181
done
8282

83-
# Currently only git-lfs works from offsite:
84-
if ! [[ $(hostname) == *.jlab.org ]]; then
85-
echo "INFO: using --lfs for offsite usage"
83+
# count how many data-retrieval options are set
84+
count_download_opts() {
85+
local n=0
86+
for o in $useLfs $useCvmfs $useXrootd; do
87+
$o && ((n++))
88+
done
89+
echo $n
90+
}
91+
92+
# if the user did not choose a data retrieval method, choose a reasonable one
93+
if [[ $(count_download_opts) -eq 0 ]]; then
94+
echo 'INFO: no data-retrieval option set; choosing a default...'
95+
if ! [[ $(hostname) == *.jlab.org ]]; then
96+
echo 'INFO: ... using `--lfs` since you are likely offsite'
8697
useLfs=true
98+
elif [ -d /cvmfs ]; then
99+
echo 'INFO: ... using `--cvmfs` since you are likely onsite and have /cvmfs'
100+
useCvmfs=true
101+
else
102+
echo 'WARNING: default data-retrieval option cannot be determined; use `--help` for guidance' >&2
103+
sleep 1
104+
fi
105+
fi
106+
107+
# if they chose too many, fail
108+
if [[ $(count_download_opts) -gt 1 ]]; then
109+
echo 'ERROR: more than one data-retrieval option is set' >&2
110+
exit 1
87111
fi
88112

89113

0 commit comments

Comments
 (0)