|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | # Pants wrapper script that auto-installs pants if not already available |
3 | | -# |
| 3 | +# |
4 | 4 | # This wrapper is installed to /usr/local/bin/pants during Copilot setup. |
5 | 5 | # It allows users to just run "pants" without worrying about installation. |
6 | 6 | # |
|
13 | 13 |
|
14 | 14 | set -euo pipefail |
15 | 15 |
|
16 | | -# Check if pants exists in ~/.local/bin (default install location) |
17 | | -if [ -x "$HOME/.local/bin/pants" ]; then |
18 | | - exec "$HOME/.local/bin/pants" "$@" |
19 | | -fi |
| 16 | +GET_PANTS="${GET_PANTS:-}" |
20 | 17 |
|
21 | | -# pants is not installed, install it now |
22 | | -echo "Pants not found. Installing pants..." >&2 |
23 | 18 |
|
24 | | -# Find the repository root (where get-pants.sh should be) |
25 | | -REPO_ROOT="${REPO_ROOT:-}" |
26 | | -if [ -z "$REPO_ROOT" ]; then |
27 | | - # Try to find get-pants.sh |
28 | | - if [ -f "get-pants.sh" ]; then |
29 | | - REPO_ROOT="$(pwd)" |
30 | | - elif [ -f "../get-pants.sh" ]; then |
31 | | - REPO_ROOT="$(cd .. && pwd)" |
32 | | - elif [ -f "/home/runner/work/toolshed/toolshed/get-pants.sh" ]; then |
33 | | - REPO_ROOT="/home/runner/work/toolshed/toolshed" |
34 | | - else |
35 | | - echo "Error: Cannot find get-pants.sh. Please set REPO_ROOT or run from repository directory." >&2 |
36 | | - exit 1 |
| 19 | +run_pants () { |
| 20 | + if [[ -x "$HOME/.local/bin/pants" ]]; then |
| 21 | + exec "$HOME/.local/bin/pants" "$@" |
| 22 | + exit 0 |
37 | 23 | fi |
38 | | -fi |
| 24 | +} |
39 | 25 |
|
40 | | -# Run get-pants.sh to install pants |
41 | | -if [ -f "$REPO_ROOT/get-pants.sh" ]; then |
42 | | - echo "Running get-pants.sh from $REPO_ROOT..." >&2 |
43 | | - cd "$REPO_ROOT" |
44 | | - ./get-pants.sh |
45 | | - |
46 | | - # Now that pants is installed, execute it |
47 | | - if [ -x "$HOME/.local/bin/pants" ]; then |
48 | | - exec "$HOME/.local/bin/pants" "$@" |
49 | | - else |
50 | | - echo "Error: pants installation failed" >&2 |
51 | | - exit 1 |
| 26 | +find_get_pants () { |
| 27 | + if [[ -z "$GET_PANTS" ]]; then |
| 28 | + # Try to find get-pants.sh |
| 29 | + if [[ -f "get-pants.sh" ]]; then |
| 30 | + GET_PANTS="$(realpath ./get-pants.sh)" |
| 31 | + elif [[ -f "../get-pants.sh" ]]; then |
| 32 | + GET_PANTS="$(realpath ../get-pants.sh)" |
| 33 | + elif [[ -f "/home/runner/work/toolshed/toolshed/get-pants.sh" ]]; then |
| 34 | + GET_PANTS="/home/runner/work/toolshed/toolshed/get-pants.sh" |
| 35 | + else |
| 36 | + echo "Error: Cannot find get-pants.sh. Please set GET_PANTS or run from repository directory." >&2 |
| 37 | + exit 1 |
| 38 | + fi |
52 | 39 | fi |
53 | | -else |
54 | | - echo "Error: get-pants.sh not found in $REPO_ROOT" >&2 |
55 | | - exit 1 |
56 | | -fi |
| 40 | + if [[ ! -f "$GET_PANTS" ]]; then |
| 41 | + echo "Error: Cannot find get-pants.sh (${GET_PANTS})." >&2 |
| 42 | + fi |
| 43 | +} |
| 44 | + |
| 45 | +install_pants () { |
| 46 | + echo "Pants not found. Installing pants..." >&2 |
| 47 | + find_get_pants |
| 48 | + echo "Running get-pants.sh from $GET_PANTS..." >&2 |
| 49 | + "${GET_PANTS}" |
| 50 | +} |
| 51 | + |
| 52 | +run_pants "${@}" |
| 53 | +install_pants |
| 54 | +run_pants "${@}" |
| 55 | +echo "Error: pants installation failed" >&2 |
| 56 | +exit 1 |
0 commit comments