forked from JeffersonLab/coatjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-clara
More file actions
executable file
·153 lines (133 loc) · 4.77 KB
/
install-clara
File metadata and controls
executable file
·153 lines (133 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
set -e
# Default versions:
grapes=2.20
clara=5.0.2
function error() {
echo -e "\n$usage\n\n Use option '-h' for more usage guidance.\n\nERROR: $@"
exit 1
}
function get() {
[ "$debug" -eq 0 ] && wopts="--no-verbose" || wopts=""
[ "$#" -gt 1 ] && topts="-C $2 -xz" || topts="-xz"
[ "$debug" -gt 0 ] && topts+="v"
wget $wopts $1
tar $topts -f $(basename $1)
}
function install() {
find clara-cre -exec touch {} +
chmod -f -R a+r clara-cre
chmod -f a+x clara-cre/bin/*
mv clara-cre $clara_home
}
function litter() {
exit_code=$1
if [ -d "$tmp_dir" ]
then
if [ "$exit_code" -ne 0 ] || [ "$debug" -gt 1 ]
then
echo -e "\nSee temporary build directory for more info:\n\t$tmp_dir"
else
rm -rf $tmp_dir
fi
fi
}
function check() {
if compgen -G "$clara_home/lib/jclara-*.jar" > /dev/null
then
echo -e "\n\$CLARA_HOME installed at:\n\t$clara_home\n"
else
echo -e "\n\$CLARA_HOME installed but looks broken:\n\t$clara_home"
fi
}
function cleanup() {
exit_code=$?
[ "$exit_code" -eq 0 ] && install
litter $exit_code
[ "$exit_code" -eq 0 ] && check
}
function build_clara {
#git clone --branch $clara --depth 1 https://code.jlab.org/hallb/clas12/clara-java
git clone --depth 1 https://code.jlab.org/hallb/clas12/clara-java
cd clara-java && CLARA_HOME=$1 ./gradlew deploy && cd -
}
function build_grapes {
#git clone --branch $grapes --depth 1 https://code.jlab.org/hallb/clas12/coatjava/grapes
git clone --depth 1 https://code.jlab.org/hallb/clas12/coatjava/grapes
cd grapes && mvn package && cd -
}
trap cleanup EXIT
# Configure:
debug=0
args=()
usage="Usage: install-clara [-v] [-b] [-c COATJAVA] [-f CLARA] [-g GRAPES] PATH"
info="""
- The default CLARA / GRAPES versions are $clara / $grapes
- COATJAVA can also be specified as a local installation directory
- If the COATJAVA version is not specified, it will try to auto-detect it.
- [-v adds verbosity and disables cleanup]
- [-b builds clara from source]"""
while [[ $# -gt 0 ]]
do
case $1 in
-h|--help) echo -e "\n$usage" && echo -e "$info" && exit 1 ;;
-f) clara="$2" && shift && shift ;;
-c) coatjava="$2" && shift && shift ;;
-g) grapes="$2" && shift && shift ;;
-b) build=1 && shift ;;
-v) let debug=$debug+1 && shift ;;
-*|--*) echo -e "$usage\n\nUnknown option: $1" && exit 1 ;;
*) args+=("$1") && shift ;;
esac
done
# Check requested installation path:
clara_home="$args"
[ "${#args[@]}" -lt 1 ] && error "Missing PATH argument"
[ "${#args[@]}" -gt 1 ] && error "Extra PATH arguments: ${args[@]:1}"
[ -e "$clara_home" ] && error "Installation PATH already exists: $clara_home"
mkdir -p $clara_home || error "Cannot create installation PATH: $clara_home"
clara_home=$(cd $clara_home && pwd) && rmdir $clara_home
# If the user didn't specify a coatjava version, try auto-detect the version:
if [ -z ${coatjava+x} ]
then
[ -e "$(dirname $0)/libexec/version.sh" ] || error "Failed to auto-detect. COATJAVA version must be specified with '-c'"
coatjava=$($(dirname $0)/libexec/version.sh | sed 's/-SNAPSHOT//')
fi
# Detect local COATJAVA installation and convert into an absolute path:
if compgen -G "$coatjava/lib/clas/coat-libs-*.jar" > /dev/null
then
coatjava=$(cd $coatjava && pwd)
echo -e "\nUsing local COATJAVA installation:\n\t$coatjava"
elif ! [[ "$coatjava" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)t?$ ]] # must be semver, or semver+"t"
then
echo -e "\n\nWARNING: COATJAVA doesn't look like a local installation nor version number: $coatjava"
fi
# Do everything inside a new, temporary directory:
[ -w "." ] || error "Current working directory is not writeable: \$PWD=$PWD"
tmp_dir=$(mktemp -d tmp.install-clara.XXXXXX)
[ $? -ne 0 ] && error "Cannot create temporary directory: $tmp_dir"
tmp_dir=$(cd $tmp_dir && pwd)
cd $tmp_dir
# CLARA:
if ! [ -z ${build+x} ]
then
echo -e "\nBuilding CLARA from source ..."
build_clara $PWD/clara-cre
else
echo -e "\nRetrieving CLARA version $clara ..."
get https://clasweb.jlab.org/clas12offline/distribution/clara/clara-cre-$clara.tar.gz
fi
# COATJAVA:
if ! compgen -G "$coatjava/lib/clas/coat-libs-*.jar" > /dev/null
then
echo -e "\nRetrieving COATJAVA version $coatjava ..."
get https://github.com/JeffersonLab/coatjava/releases/download/$coatjava/coatjava-$coatjava.tar.gz
coatjava=./coatjava-$coatjava
fi
mkdir -p clara-cre/plugins/clas12/config
cp -Lr $coatjava/etc $coatjava/bin $coatjava/lib* clara-cre/plugins/clas12
# GRAPES:
echo -e "\nRetrieving GRAPES version $grapes ..."
build_grapes $PWD/grapes
mkdir -p clara-cre/plugins/grapes/lib/core/
cp grapes/target/grapes-*core*.jar clara-cre/plugins/grapes/lib/core/