|
6 | 6 | # when the command is finished. This script should be dropped when this |
7 | 7 | # repository is a proper Go module with a permanent go.mod. |
8 | 8 |
|
9 | | -set -e |
| 9 | +set -euo pipefail |
10 | 10 |
|
11 | 11 | SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
12 | 12 | ROOTDIR="$(cd "${SCRIPTDIR}/.." && pwd)" |
13 | 13 |
|
14 | | -if test -e "${ROOTDIR}/go.mod"; then |
15 | | - { |
16 | | - scriptname=$(basename "$0") |
17 | | - cat >&2 <<- EOF |
18 | | - $scriptname: WARN: go.mod exists in the repository root! |
19 | | - $scriptname: WARN: Using your go.mod instead of our generated version -- this may misbehave! |
20 | | - EOF |
21 | | - } >&2 |
22 | | -else |
| 14 | +cleanup_paths="" |
| 15 | +create_symlink() { |
| 16 | + local target="$1" |
| 17 | + local link="$2" |
| 18 | + |
| 19 | + pushd "${ROOTDIR}" > /dev/null |
| 20 | + trap 'popd > /dev/null' RETURN |
| 21 | + |
| 22 | + if [ -L "$link" ] && [ "$(readlink "$link")" = "$target" ]; then |
| 23 | + # symlink already present; we're done |
| 24 | + return |
| 25 | + fi |
| 26 | + |
| 27 | + if [ -e "$link" ]; then |
| 28 | + echo "$(basename "$0"): WARN: $link exists but is not the expected symlink!" >&2 |
| 29 | + echo "$(basename "$0"): WARN: Using your version instead of our generated version -- this may misbehave!" >&2 |
| 30 | + return |
| 31 | + fi |
| 32 | + |
23 | 33 | set -x |
| 34 | + ln -s "$target" "$link" |
| 35 | + cleanup_paths="$cleanup_paths ${ROOTDIR}/$link" |
| 36 | +} |
24 | 37 |
|
25 | | - tee "${ROOTDIR}/go.mod" >&2 <<- EOF |
26 | | - module github.com/docker/cli |
| 38 | +create_symlink "vendor.mod" "go.mod" |
| 39 | +create_symlink "vendor.sum" "go.sum" |
27 | 40 |
|
28 | | - go 1.23.0 |
29 | | - EOF |
30 | | - trap 'rm -f "${ROOTDIR}/go.mod"' EXIT |
| 41 | +if [ -n "$cleanup_paths" ]; then |
| 42 | + trap 'rm -f'"$cleanup_paths" EXIT |
31 | 43 | fi |
32 | 44 |
|
33 | 45 | GO111MODULE=on GOTOOLCHAIN=local "$@" |
0 commit comments