aboutsummaryrefslogtreecommitdiff
path: root/tools/gen-source-tar.sh
blob: 66c04caf090ab5d830b5fa33417e28c3c3e3b851 (plain)
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
#!/bin/bash

set -e

: ${SOURCE_INSTALL_METHOD:=git}
: ${GIT_REF:=master}
: ${LOCAL_SOURCE:=/tmp/${COMPONENT}}

function fetch_source_from_uri {
    curl ${TARBALL_URI} -o ${TMPDIR}/${COMPONENT}.tar
}

function fetch_source_from_git {
    # NOTE(pbourke): do a shallow clone to master only, unless a specific ref is
    # required
    if [ -z ${GIT_REF} ]; then
        git clone --depth=1 ${CLONE_FROM} ${TMPDIR}/${COMPONENT}
    else
        git clone ${CLONE_FROM} ${TMPDIR}/${COMPONENT}
        git --git-dir ${TMPDIR}/${COMPONENT}/.git checkout ${GIT_REF}
    fi
    tar -cf ${TMPDIR}/${COMPONENT}.tar -C ${TMPDIR} ${COMPONENT}
}

function fetch_source_from_local {
    tar -cf ${TMPDIR}/${COMPONENT}.tar \
        -C $(dirname ${LOCAL_SOURCE}) ${COMPONENT}
}

case ${SOURCE_INSTALL_METHOD} in
    curl)
        fetch_source_from_uri
        ;;
    git)
        fetch_source_from_git
        ;;
    local)
        fetch_source_from_local
        ;;
    *)
        cat << EOF
Unknown install method '${SOURCE_INSTALL_METHOD}'. Please check the value of
\$SOURCE_INSTALL_METHOD in .buildconf
EOF
        exit 1
        ;;
esac