duneci-install-module 2.58 KB
Newer Older
1
2
3
4
#! /bin/bash
# Author: Ansgar Burchardt <Ansgar.Burchardt@tu-dresden.de>

set -e
Ansgar Burchardt's avatar
Ansgar Burchardt committed
5
set -u
6
7

usage() {
Ansgar Burchardt's avatar
Ansgar Burchardt committed
8
9
10
11
    echo "usage: duneci-install-module [options] <Git-repository> <dunecontrol-opts>" >&2
    echo >&2
    echo "options:" >&2
    echo "  -b <branch>, --branch <branch>: Install branch <branch> of the module." >&2
12
    echo "  -r, --recursive: Clone the git repository with --recursive (for git submodules)." >&2
Ansgar Burchardt's avatar
Ansgar Burchardt committed
13
14
15
16
17
18
19
    echo >&2
    echo "environment variables:" >&2
    echo "  DUNECI_BRANCH:" >&2
    echo "      branch to use if none is specified via -b|--branch;" >&2
    echo "      empty for default branch (usually 'master'); default: ''" >&2
    echo "  DUNECI_BRANCH_AUTO:" >&2
    echo "      if '1', try to use the same branch as build by the CI system," >&2
20
    echo "      that is \${CI_BUILD_REF_NAME};  default: '1'" >&2
21
22
23
24
25
26
27
    exit ${1:-0}
}

if [[ $# -eq 0 ]]; then
    usage 0
fi

Ansgar Burchardt's avatar
Ansgar Burchardt committed
28
29

branch="${DUNECI_BRANCH:-}"
30
recursive=0
Ansgar Burchardt's avatar
Ansgar Burchardt committed
31
32
33
34
35
36
37

while :; do
    case "${1}" in
        -b|--branch)
            branch="${2}"
            shift 2
            ;;
38
39
40
41
        -r|--recursive)
            recursive=1
            shift 1
            ;;
Ansgar Burchardt's avatar
Ansgar Burchardt committed
42
43
44
45
46
47
        *)
            break
            ;;
    esac
done

48
49
50
51
52
53
54
55
56
57
repo="${1}"
module="${repo##*/}"; module="${module%.git}"
shift

cd /duneci/modules
if [[ -d "${module}" ]]; then
    echo "Module ${module} is already installed." >&2
    exit 1
fi

58
git_clone_opts=(--depth=1 --no-single-branch "${recursive}")
Ansgar Burchardt's avatar
Ansgar Burchardt committed
59
60
61
if [[ -n "${branch}" ]]; then
    git_clone_opts+=(-b "${branch}")
fi
62
63
64
if [[ ${recursive} ]]; then
    git_clone_opts+=("--recursive")
fi
Ansgar Burchardt's avatar
Ansgar Burchardt committed
65
66

git clone "${git_clone_opts[@]}" "${repo}"
67
if [[ "${DUNECI_BRANCH_AUTO:-1}" = "1" && -n "${CI_BUILD_REF_NAME:-}" ]]; then
Ansgar Burchardt's avatar
Ansgar Burchardt committed
68
69
    # It is not an error if ${CI_BUILD_REF_NAME} is not a branch
    # in the module we are about to install.
70
    git -C "${module}" checkout "${CI_BUILD_REF_NAME}" || :
Ansgar Burchardt's avatar
Ansgar Burchardt committed
71
72
fi

73
74
75
76
77
78
79
80
81
if [[ "${module}" = dune-common ]]; then
    for f in dunecontrol dune-ctest; do
        src=/duneci/modules/dune-common/bin/${f}
        if [[ -x ${src} ]]; then
            ln -sf ${src} /duneci/bin/
        fi
    done
fi

82
83
opts="${DUNECI_OPTS:-/duneci/opts.gcc}"

84
85
86
87
if [[ -v DUNECI_PARALLEL ]]; then
    set -- --make-opts="-j${DUNECI_PARALLEL}" "${@}"
fi

88
89
(
    cd "${module}"
90
    git_branch=$(git symbolic-ref HEAD 2>/dev/null || echo "(unknown)")
91
92
93
94
95
    git_branch="${git_branch#refs/heads/}"
    echo
    echo "Installing ${module}; branch ${git_branch}"
    echo "  commit: $(git rev-parse HEAD)"
    echo "  date:   $(git log -1 --format='tformat:%ci') (commit)"
96
    echo "  using opts file ${opts}"
97
98
99
    echo
)

100
dunecontrol --opts="${opts}" "${@}" --only="${module}" all