Repository navigation
Expand file tree
/
Copy pathrun-tool
More file actions
executable file
·43 lines (37 loc) · 1.66 KB
/
Copy pathrun-tool
File metadata and controls
executable file
·43 lines (37 loc) · 1.66 KB
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
#!/usr/bin/env bash
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
# Consumer repositories install this runner as .devcontainer/run-tool.
# It runs a pinned CLI tool from PATH in a container or through Bazel on the host.
# See https://github.com/eclipse-score/devcontainer/tree/main/tools.
set -euo pipefail
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 <tool> [args...]" >&2
exit 2
fi
tool_name="$1"
shift
# A host PATH may contain an arbitrary, unpinned version, so PATH execution is
# deliberately limited to containers built from this catalog. If a container
# lacks a command, falling through to Bazel still gives it the pinned version.
if { [[ -f /.dockerenv ]] || [[ -f /run/.containerenv ]] || [[ -d /devcontainer ]]; } &&
command -v "${tool_name}" >/dev/null 2>&1; then
exec "${tool_name}" "$@"
elif command -v bazel >/dev/null 2>&1; then
# Consumer repositories expose this module as @score_devcontainer; `--`
# prevents tool flags from being interpreted as Bazel flags.
exec bazel run "@score_devcontainer//tools:${tool_name}" -- "$@"
else
echo "Could not run '${tool_name}': no container command or Bazel executable is available." >&2
exit 127
fi