forked from NNPDF/pineappl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-capi.sh
executable file
·82 lines (69 loc) · 2.05 KB
/
install-capi.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
#!/bin/sh
set -eu
if command -v gcc >/dev/null; then
target=$(gcc -dumpmachine)
case ${target} in
arm64-apple-darwin*) target=aarch64-apple-darwin;;
x86_64-*-linux-gnu | x86_64-linux-gnu | x86_64-*-linux) target=x86_64-unknown-linux-gnu;;
x86_64-apple-darwin*) target=x86_64-apple-darwin;;
*) echo "Error: target '${target}' unknown."; exit 1;;
esac
else
echo "Error: target unknown."
exit 1
fi
prefix=
version=
while [ $# -gt 0 ]; do
case $1 in
--version)
version=$2
shift
shift
;;
--version=*)
version=${1#--version=}
shift
;;
--prefix)
prefix=$2
shift
shift
;;
--prefix=*)
prefix=${1#--prefix=}
shift
;;
*)
echo "Error: argument '$1' unknown"
exit 1
;;
esac
done
# if no prefix is given, prompt for one
if [ -z ${prefix} ]; then
# read from stdin (`<&1`), even if piped into a shell
read -p "Enter installation path: " <&1 prefix
fi
if [ ! -d "${prefix}" ]; then
mkdir -p "${prefix}"
fi
# if no version is given, use the latest version
if [ -z ${version} ]; then
version=$(curl -s https://api.github.com/repos/NNPDF/pineappl/releases/latest | \
sed -n 's/[ ]*"tag_name"[ ]*:[ ]*"v\([^"]*\)"[ ]*,[ ]*$/\1/p')
fi
base_url=https://github.com/NNPDF/pineappl/releases/download
echo "prefix: ${prefix}"
echo "target: ${target}"
echo "version: ${version}"
# we need the absolute path
cd "${prefix}"
prefix=$(pwd)
cd - >/dev/null
curl -s -LJ "${base_url}"/v${version}/pineappl_capi-${target}.tar.gz \
| tar xzf - -C "${prefix}"
# instead of `sed` and `mv` we could use `sed -i`, but on Mac it doesn't work as expected from GNU sed
sed s:prefix=/:prefix=${prefix}: "${prefix}"/lib/pkgconfig/pineappl_capi.pc > \
"${prefix}"/lib/pkgconfig/pineappl_capi.pc.new
mv "${prefix}"/lib/pkgconfig/pineappl_capi.pc.new "${prefix}"/lib/pkgconfig/pineappl_capi.pc