dev 951 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. # Simple dev tool launcher - builds if needed
  3. set -euo pipefail
  4. # Colors
  5. GREEN='\033[0;32m'
  6. RED='\033[0;31m'
  7. NC='\033[0m'
  8. log() { echo -e "${GREEN}[DEV]${NC} $*"; }
  9. error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
  10. # Simple platform detection
  11. ARCH=$(uname -m)
  12. case $ARCH in
  13. x86_64) ARCH="amd64" ;;
  14. arm64 | aarch64) ARCH="arm64" ;;
  15. *)
  16. error "Unsupported arch: $ARCH"
  17. exit 1
  18. ;;
  19. esac
  20. BINARY="bin/dev-linux-$ARCH"
  21. # Build if binary doesn't exist or source is newer
  22. if [[ ! -f "$BINARY" ]] || [[ "main.go" -nt "$BINARY" ]]; then
  23. if ! command -v go &>/dev/null; then
  24. error "Go not installed. Install with: sudo pacman -S go"
  25. exit 1
  26. fi
  27. log "Building dev tool..."
  28. mkdir -p bin
  29. go mod tidy
  30. if go build -ldflags="-s -w" -o "$BINARY" main.go; then
  31. log "✅ Built: $BINARY"
  32. else
  33. error "Build failed"
  34. exit 1
  35. fi
  36. fi
  37. # Run the binary
  38. exec "$BINARY" "$@"