-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·223 lines (162 loc) · 4.88 KB
/
install.sh
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/sh
BUILDTEMP=$(mktemp -d)
error_out()
{
echo "$@"
if test -d "${BUILDTEMP}"; then
# Cleanup all temps
rm -fr "${BUILDTEMP}"
fi
exit 1
}
locate_bin()
{
which "$@" > /dev/null 2>&1
}
assert_is_file()
{
if test ! -f "${1}"; then
error_out "Failed to locate file ${1}"
fi
}
header()
{
echo "======================="
echo "$@"
echo "======================="
}
check_dir()
{
if test ! -d "$1"; then
mkdir "$1"
fi
}
if test $# = 1; then
echo "Installing in ${1}"
PREFIX="${1}"
else
error_out "Please provide an install prefix: $0 [PREFIX]"
fi
if test ! -d "${PREFIX}"; then
mkdir "${PREFIX}" || error_out "Failed to create ${PREFIX} directory"
fi
header "Locate Rust Dependency"
if locate_bin "cargo"; then
echo "Rust found in environment"
else
error_out "Rust not found in environment"
fi
if locate_bin "cbindgen"; then
echo "cbindgen found in path"
else
error_out "Failed to locate cbindgen consider running 'cargo install cbindgen'"
fi
header "Build Project"
# Root of Package
DIRNAME=$(dirname "$0")
SOURCE_ROOT="$(readlink -f "${DIRNAME}")"
export SOURCE_ROOT
cargo build --release || error_out "Failed to build package see previous errors"
cargo install --path "${SOURCE_ROOT}" --root "${PREFIX}" || error_out "Failed to install rust package"
# The Build Directory
BUILD_SOURCE_ROOT=""
if test -d "$SOURCE_ROOT/target/debug"; then
BUILD_SOURCE_ROOT="$SOURCE_ROOT/target/debug"
elif test -d "$SOURCE_ROOT/target/release"; then
BUILD_SOURCE_ROOT="$SOURCE_ROOT/target/release"
else
error_out "Cannot locate build, did 'cargo build' succeed ?"
fi
echo "Using Build directory ${BUILD_SOURCE_ROOT}"
#
# Deploy the Client Libary and its header
#
header "Deploy Client Library"
check_dir "${PREFIX}/lib/"
check_dir "${PREFIX}/include/"
assert_is_file "${BUILD_SOURCE_ROOT}/libproxyclient.so"
cp "${BUILD_SOURCE_ROOT}/libproxyclient.so" "${PREFIX}/lib/libproxyclient.so" || error_out "Failed to install client library"
PROXY_HEADER="${PREFIX}/include/metric_proxy_client.h"
cbindgen "${SOURCE_ROOT}" -o "${PROXY_HEADER}" -l c --cpp-compat
if test -f "${PROXY_HEADER}"; then
echo "Successfully generated proxy header in ${PROXY_HEADER}"
else
error_out "Failed to generate proxy header see previous errors"
fi
check_dir "${PREFIX}/lib/pkgconfig/"
cat << EOF > "${PREFIX}/lib/pkgconfig/proxyclient.pc"
prefix=${PREFIX}
includedir=\${prefix}/include
libdir=\${prefix}/lib
Name: proxyclient
Description: Client library for the Metric Proxy
Version: 0.1
Cflags: -I\${includedir} -Wl,-rpath=\${libdir}
Libs: -L\${libdir} -lproxyclient -Wl,-rpath=\${libdir}
EOF
#
# Build dep detection
#
header "Detecting build dependencies"
# Detect Python
PYTHON=""
if test -z "$PYTHON"; then
if locate_bin "python3"; then
PYTHON="python3"
elif locate_bin "python"; then
PYTHON="python"
else
error_out "Failed to locate python consider setting the PYTHON environment variable to your interpreter"
fi
fi
echo "Using Python : ${PYTHON}"
# Detect MPICC
MPICC=""
if test -z "$MPICC"; then
if locate_bin "mpicc"; then
MPICC="mpicc"
else
error_out "Failed to locate mpicc compiler wrappers consider setting the MPICC environment variable"
fi
fi
echo "Using MPICC : ${MPICC}"
#
# Generate the MPI Wrappers
#
header "Generating MPI Wrappers"
MPIWRAP="${SOURCE_ROOT}/exporters/mpi/dist/llnl_mpiwrap/wrap.py"
assert_is_file "$MPIWRAP"
MPI_WRAPPER_SOURCES="${SOURCE_ROOT}/exporters/mpi/mpi_wrappers.w"
assert_is_file "$MPI_WRAPPER_SOURCES"
MPI_WRAPPERS_C="${BUILDTEMP}/mpi_wrappers.c"
"${PYTHON}" "${MPIWRAP}" -f "${MPI_WRAPPER_SOURCES}" > "${MPI_WRAPPERS_C}" || error_out "Failed to generate MPI wrappers"
if test -f "${MPI_WRAPPERS_C}"; then
echo "Successfully generated MPI wrapper sources"
else
echo "Failed to generate MPI wrappers see previous error"
fi
header "Compiling MPI Wrappers"
MPI_WRAPPER_LIB="${PREFIX}/lib/libmetricproxy-exporter-mpi.so"
"${MPICC}" "-I${PREFIX}/include/" "-I${SOURCE_ROOT}/exporters/mpi/" "-L${PREFIX}/lib" "-Wl,-rpath=${PREFIX}/lib" -shared -fpic "${MPI_WRAPPERS_C}" -lproxyclient -o "${MPI_WRAPPER_LIB}"
if test -f "${MPI_WRAPPER_LIB}"; then
echo "Successfully generated MPI wrapper library"
else
error_out "Failed to generate MPI wrappers library"
fi
#
# Deploy the Modified Strace
#
header "Deploying Modified Strace"
if test ! -f "${PREFIX}/bin/proxy_exporter_strace"; then
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig/:$PKG_CONFIG_PATH"
cd "${SOURCE_ROOT}/exporters/strace/" || error_out "Failed to enter strace sourcedir"
./bootstrap || error_out "Failed to bootstrap strace"
cd "${BUILDTEMP}" || error_out "Failed to move to ${BUILDTEMP}"
${SOURCE_ROOT}/exporters/strace/configure --prefix=${PREFIX} --program-prefix=proxy_exporter_ --enable-mpers=no || error_out "Failed to configure strace"
make install -j8 || error_out "Failed to install strace"
echo "Sucessfully deployed"
else
echo "Already installed"
fi
# All done if we are here
rm -fr "${BUILDTEMP}"