install-shared.bash 2.2 KB
Newer Older
1
2
3
4
5
6
7
#!/usr/bin/env bash

download_release_tarball() {
    __resultvar=$1
    __submodule_path=$2
    __repo_name=$(echo $2 | cut -d '/' -f 1)
    __release_name="${__repo_name}-$(uname)"
8
    __release_sha1=$(git rev-parse HEAD:"${__submodule_path}")
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    __release_tag="${__release_sha1:0:16}"
    __release_tag_url="https://api.github.com/repos/filecoin-project/${__repo_name}/releases/tags/${__release_tag}"

    echo "acquiring release @ ${__release_tag}"

    __release_response=$(curl \
        --retry 3 \
        --location $__release_tag_url)

    __release_url=$(echo $__release_response | jq -r ".assets[] | select(.name | contains(\"${__release_name}\")) | .url")

    if [[ -z "$__release_url" ]]; then
        (>&2 echo "failed to download release (tag URL: ${__release_tag_url}, response: ${__release_response})")
        return 1
    fi

    __tar_path="/tmp/${__release_name}_$(basename ${__release_url}).tar.gz"

27
28
29
30
31
32
33
34
35
36
37
38
39
    __asset_url=$(curl \
        --head \
        --retry 3 \
        --header "Accept:application/octet-stream" \
        --location \
        --output /dev/null \
        -w %{url_effective} \
        "$__release_url")

    curl --retry 3 --output "${__tar_path}" "$__asset_url"
    if [[ $? -ne "0" ]]; then
        (>&2 echo "failed to download release asset (tag URL: ${__release_tag_url}, asset URL: ${__asset_url})")
        return 1
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
    fi

    eval $__resultvar="'$__tar_path'"
}

build_from_source() {
    __submodule_path=$1
    __submodule_sha1=$(git rev-parse @:"${__submodule_path}")
    __submodule_sha1_truncated="${__submodule_sha1:0:16}"

    echo "building from source @ ${__submodule_sha1_truncated}"

    if ! [ -x "$(command -v cargo)" ]; then
        (>&2 echo 'Error: cargo is not installed.')
        (>&2 echo 'Install Rust toolchain to resolve this problem.')
        exit 1
    fi

    if ! [ -x "$(command -v rustup)" ]; then
        (>&2 echo 'Error: rustup is not installed.')
        (>&2 echo 'Install Rust toolchain installer to resolve this problem.')
        exit 1
    fi

    pushd $__submodule_path

    cargo --version

    if [[ -f "./scripts/build-release.sh" ]]; then
        ./scripts/build-release.sh $(cat rust-toolchain)
    else
        cargo build --release --all
    fi

    popd
}