-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·42 lines (33 loc) · 1.33 KB
/
setup.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
#!/bin/bash
# ci-tools -- setup.sh
# Downloads and setup tools from @SGSGermany's `ci-tools` collection.
#
# Copyright (c) 2021 SGS Serious Gaming & Simulations GmbH
#
# This work is licensed under the terms of the MIT license.
# For a copy, see LICENSE file or <https://opensource.org/licenses/MIT>.
#
# SPDX-License-Identifier: MIT
# License-Filename: LICENSE
set -eu -o pipefail
export LC_ALL=C
GITHUB_SERVER_URL="https://github.com"
REPOSITORY="SGSGermany/ci-tools"
GIT_DIR="${1:-}"
[ -n "$GIT_DIR" ] || GIT_DIR="$(mktemp -d)"
GIT_REF="${2:-}"
[ -n "$GIT_REF" ] || GIT_REF="refs/heads/main"
echo "Preparing 'ci-tools' repository..." >&2
[ -d "$GIT_DIR" ] || mkdir "$GIT_DIR"
cd "$GIT_DIR"
git init >&2
git remote add "origin" "$GITHUB_SERVER_URL/$REPOSITORY.git" >&2
echo "Fetching '$GIT_REF' from '$GITHUB_SERVER_URL/$REPOSITORY.git'..." >&2
[[ "$GIT_REF" != refs/* ]] || GIT_REF="$(git ls-remote --refs origin "$GIT_REF" | tail -n1 | cut -f1)"
git fetch --depth 1 origin "$GIT_REF" >&2
echo "Checking out commit $GIT_REF from $(git show -s --format=%ci FETCH_HEAD)..." >&2
git checkout --detach "$GIT_REF" >&2
echo "Setting 'CI_TOOLS' environment variable: SGSGermany" >&2
printf 'export %s="%s"\n' "CI_TOOLS" "SGSGermany"
echo "Setting 'CI_TOOLS_PATH' environment variable: $GIT_DIR/src" >&2
printf 'export %s="%s"\n' "CI_TOOLS_PATH" "$GIT_DIR/src"