|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +BLUE='\033[1;34m' |
| 5 | +GREEN='\033[1;32m' |
| 6 | +RED='\033[1;31m' |
| 7 | +NC='\033[0m' |
| 8 | + |
| 9 | +NODE_NAME="pulsar-field-node" |
| 10 | + |
| 11 | +# Dependency check |
| 12 | +if ! command -v multipass &> /dev/null; then |
| 13 | + echo -e "${RED}❌ Multipass is not installed.${NC}" |
| 14 | + echo "Please install it via: brew install --cask multipass" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +echo -e "${BLUE}=== Provisioning Tier 3 Linux Field Node ===${NC}" |
| 19 | + |
| 20 | +# Clean up existing instance if it exists |
| 21 | +if multipass info "$NODE_NAME" &> /dev/null; then |
| 22 | + echo -e "ℹ Destroying existing node '$NODE_NAME'..." |
| 23 | + multipass delete "$NODE_NAME" |
| 24 | + multipass purge |
| 25 | +fi |
| 26 | + |
| 27 | +echo -e "ℹ Launching fresh Ubuntu instance (cached images boot in ~5s)..." |
| 28 | +multipass launch --name "$NODE_NAME" |
| 29 | + |
| 30 | +echo -e "ℹ Waiting for VM networking and SSHFS to stabilize..." |
| 31 | +multipass exec "$NODE_NAME" -- bash -c "while ! id -g >/dev/null 2>&1; do sleep 1; done" |
| 32 | + |
| 33 | +echo -e "ℹ Preparing mount point..." |
| 34 | +multipass exec "$NODE_NAME" -- sudo mkdir -p /mnt/pulsar-source |
| 35 | +multipass exec "$NODE_NAME" -- sudo chown ubuntu:ubuntu /mnt/pulsar-source |
| 36 | + |
| 37 | +echo -e "ℹ Mounting git-pulsar source code (Retrying until VM is ready)..." |
| 38 | +MAX_RETRIES=5 |
| 39 | +RETRY_COUNT=0 |
| 40 | +MOUNT_SUCCESS=false |
| 41 | + |
| 42 | +while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do |
| 43 | + if multipass mount "$(pwd)" "$NODE_NAME":/mnt/pulsar-source &> /dev/null; then |
| 44 | + MOUNT_SUCCESS=true |
| 45 | + break |
| 46 | + fi |
| 47 | + echo -e " [Wait] SSHFS not ready, retrying in 3s... ($((RETRY_COUNT+1))/$MAX_RETRIES)" |
| 48 | + sleep 3 |
| 49 | + RETRY_COUNT=$((RETRY_COUNT+1)) |
| 50 | +done |
| 51 | + |
| 52 | +if [ "$MOUNT_SUCCESS" = false ]; then |
| 53 | + echo -e "${RED}❌ Fatal: Could not mount directory after $MAX_RETRIES attempts.${NC}" |
| 54 | + exit 1 |
| 55 | +fi |
| 56 | + |
| 57 | +echo -e "ℹ Bootstrapping Python environment (uv)..." |
| 58 | +multipass exec "$NODE_NAME" -- bash -c "curl -LsSf https://astral.sh/uv/install.sh | sh" |
| 59 | + |
| 60 | +echo -e "ℹ Configuring global Git identity for shadow commits..." |
| 61 | +multipass exec "$NODE_NAME" -- git config --global user.name "Pulsar Field Tester" |
| 62 | +multipass exec "$NODE_NAME" -- git config --global user.email "[email protected]" |
| 63 | +multipass exec "$NODE_NAME" -- git config --global pull.rebase false |
| 64 | + |
| 65 | +echo -e "ℹ Creating isolated playground repository..." |
| 66 | +multipass exec "$NODE_NAME" -- bash -c "mkdir -p ~/playground && cd ~/playground && git init && echo '# Playground' > README.md && git add README.md && git commit -m 'Initial commit' && git branch -M main" |
| 67 | + |
| 68 | +echo -e "ℹ Installing git-pulsar into the VM..." |
| 69 | +# Using 'uv tool' installs the package globally without messing with project .venvs |
| 70 | +multipass exec "$NODE_NAME" -- bash -c "source ~/.local/bin/env && uv tool install /mnt/pulsar-source" |
| 71 | + |
| 72 | +echo -e "ℹ Setting up auto-activation and aliases..." |
| 73 | +multipass exec "$NODE_NAME" -- bash -c 'cat <<EOF >> ~/.bashrc |
| 74 | +source ~/.local/bin/env |
| 75 | +cd ~/playground |
| 76 | +alias reload-pulsar="uv tool install --force /mnt/pulsar-source" |
| 77 | +
|
| 78 | +echo -e "\n\033[1;32m✔ Git Pulsar Field Node Active.\033[0m" |
| 79 | +echo -e "You are in an isolated sandbox (~\033[1;34m/playground\033[0m). Your Mac repo is 100% safe." |
| 80 | +echo -e "Run \033[1;36mreload-pulsar\033[0m to fetch the latest code if you edit files on your Mac." |
| 81 | +EOF' |
| 82 | + |
| 83 | +echo -e "\n${GREEN}✔ Cluster Provisioned Successfully.${NC}" |
| 84 | +echo -e "\nTo begin field testing, run:" |
| 85 | +echo -e " ${BLUE}multipass shell $NODE_NAME${NC}" |
0 commit comments