hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
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
#!/bin/sh -e
# Helper to bypass AC_ERLANG_CHECK_LIB
#
# Ejabberd releases do not download specific versions of its erlang
# dependencies.  Instead, it clones the master branch of a git
# repository and asks erl to provide the library version.  However,
# the target erl program cannot be called from the host. So, this
# script aims at finding the library version installed on the target,
# without calling erlang.
 
usage() {
    cat <<EOF
Usage:
        $0 library
Look for Erlang's library in TARGET_DIR/usr/lib/erlang/lib.
 
If the library is found, it returns the path to the latest version,
relative to TARGET_DIR. Otherwise, it returns "not found".
 
If there are several versions, it returns an error because it does not
know which one Erlang uses.
 
EOF
}
 
die () {
    echo "$@" >&2
    exit 1
}
 
if [ $# -ne 1 ]; then
    usage
    exit 0
else
    library="$1"
fi
 
target_dir="${TARGET_DIR:-output/target}"
 
[ -d "$target_dir" ] || die "TARGET_DIR is not a directory. Please \
specify the TARGET_DIR environment variable."
 
case "$(ls -1d -- "$target_dir/usr/lib/erlang/lib/$library-"* | wc -l)" in
    0)
        echo "not found"
        ;;
    1)
        echo "$target_dir/usr/lib/erlang/lib/$library-"* \
            | sed -e "s,^$target_dir,,"
        ;;
    *)
        die "Several versions of $library have been found. Please \
        remove the unused ones."
        ;;
esac