|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -LIMA_VM="${LIMA_VM:-tee-builder}" |
| 4 | +# Check for dangling old-style tee-builder VM |
| 5 | +if command -v limactl &>/dev/null && limactl list 2>/dev/null | grep -q '^tee-builder '; then |
| 6 | + echo "WARNING: FOUND 'tee-builder' VM FROM BEFORE COMMIT 2b44885." |
| 7 | + echo "THIS VM IS NO LONGER USED. TO CLEAN IT UP, RUN:" |
| 8 | + echo " limactl stop tee-builder && limactl delete tee-builder" |
| 9 | + echo "" |
| 10 | +fi |
| 11 | + |
| 12 | +# Generate a unique VM name based on the absolute path of this repo |
| 13 | +# This prevents conflicts when the same repo is cloned to multiple locations |
| 14 | +REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 15 | +REPO_HASH="$(echo -n "$REPO_DIR" | sha256sum | cut -c1-8)" |
| 16 | +LIMA_VM="${LIMA_VM:-tee-builder-$REPO_HASH}" |
5 | 17 |
|
6 | 18 | # Check if Lima should be used |
7 | 19 | should_use_lima() { |
@@ -35,15 +47,15 @@ setup_lima() { |
35 | 47 | args+=("--disk" "$LIMA_DISK") |
36 | 48 | fi |
37 | 49 |
|
38 | | - echo -e "Creating $LIMA_VM VM..." |
| 50 | + echo -e "Creating Lima VM '$LIMA_VM' for $REPO_DIR..." |
39 | 51 | # Portable way to expand array on bash 3 & 4 |
40 | | - limactl create -y --name "$LIMA_VM" ${args[@]+"${args[@]}"} lima.yaml |
| 52 | + limactl create -y --name "$LIMA_VM" ${args[@]+"${args[@]}"} "$REPO_DIR/lima.yaml" |
41 | 53 | fi |
42 | 54 |
|
43 | 55 | # Start VM if not running |
44 | 56 | status=$(limactl list "$LIMA_VM" --format "{{.Status}}") |
45 | 57 | if [ "$status" != "Running" ]; then |
46 | | - echo -e "Starting $LIMA_VM VM..." |
| 58 | + echo -e "Starting Lima VM '$LIMA_VM'..." |
47 | 59 | limactl start -y "$LIMA_VM" |
48 | 60 |
|
49 | 61 | rm -f NvVars # Remove stray file created by QEMU |
@@ -111,7 +123,7 @@ if should_use_lima; then |
111 | 123 | echo |
112 | 124 | fi |
113 | 125 |
|
114 | | - echo "Note: Lima VM is still running. To stop it, run: limactl stop $LIMA_VM" |
| 126 | + echo "Note: Lima VM '$LIMA_VM' is still running. To stop it, run: limactl stop $LIMA_VM" |
115 | 127 | else |
116 | 128 | if in_nix_env; then |
117 | 129 | exec "${cmd[@]}" |
|
0 commit comments