install.sh raw

   1  #!/bin/bash
   2  set -e
   3  
   4  BASE_URL="https://moxielang.dev-releases"
   5  INSTALL_DIR="${MOXIE_INSTALL_DIR:-$HOME/.local/share/moxie}"
   6  BINDIR="${MOXIE_BINDIR:-$HOME/.local/bin}"
   7  
   8  ARCH=$(uname -m)
   9  case "$ARCH" in
  10      x86_64) ARCH=amd64 ;;
  11      aarch64) ARCH=arm64 ;;
  12      *) echo "error: unsupported arch $ARCH" >&2; exit 1 ;;
  13  esac
  14  
  15  OS=$(uname -s | tr '[:upper:]' '[:lower:]')
  16  if [ "$OS" != "linux" ]; then
  17      echo "error: only linux supported, got $OS" >&2
  18      exit 1
  19  fi
  20  
  21  PATTERN="moxie-v.*-${OS}-${ARCH}\\.tar\\.gz"
  22  
  23  echo "fetching release list ..." >&2
  24  PAGE=$(curl -sL "$BASE_URL")
  25  FILES=$(echo "$PAGE" | grep -oP '(?<=href="/moxie-releases/blob/)[^"]+\.tar\.gz' | grep -E "$PATTERN" || true)
  26  
  27  if [ -z "$FILES" ]; then
  28      echo "error: no releases found for ${OS}/${ARCH}" >&2
  29      exit 1
  30  fi
  31  
  32  LATEST=$(echo "$FILES" | sed 's/moxie-v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 &/' | sort -k1,1n -k2,2n -k3,3n | tail -1 | awk '{print $4}')
  33  
  34  echo "latest: $LATEST" >&2
  35  echo "downloading ..." >&2
  36  
  37  DL=$(mktemp -d)
  38  trap "rm -rf $DL" EXIT
  39  
  40  curl -fsSL "${BASE_URL}/raw/${LATEST}" -o "${DL}/${LATEST}"
  41  
  42  if [ -d "$INSTALL_DIR" ]; then
  43      # MOXIE_INSTALL_DIR is allowed to name a source checkout, and the
  44      # release tarball layout would replace it wholesale. Deleting a checkout
  45      # destroys work that is not the installer's to remove, so refuse loudly
  46      # and let the user pick a directory or move the checkout.
  47      if [ -e "$INSTALL_DIR/.git" ]; then
  48          echo "error: $INSTALL_DIR is a source checkout (it has .git)" >&2
  49          echo "       refusing to delete it; set MOXIE_INSTALL_DIR to the directory" >&2
  50          echo "       this installer should own (default: \$HOME/.local/share/moxie)" >&2
  51          exit 1
  52      fi
  53      echo "removing old installation ..." >&2
  54      rm -rf "$INSTALL_DIR"
  55  fi
  56  
  57  mkdir -p "$INSTALL_DIR"
  58  tar xzf "${DL}/${LATEST}" --strip-components=1 -C "$INSTALL_DIR"
  59  
  60  if [ ! -x "$INSTALL_DIR/bin/moxie" ]; then
  61      echo "error: install failed - moxie binary not found" >&2
  62      exit 1
  63  fi
  64  
  65  # extract version from tarball name and install versioned binary
  66  VNUM=$(echo "$LATEST" | grep -oP 'v\K[0-9]+\.[0-9]+\.[0-9]+')
  67  mkdir -p "$BINDIR"
  68  cp "$INSTALL_DIR/bin/moxie" "$BINDIR/moxie-${VNUM}"
  69  ln -sf "moxie-${VNUM}" "$BINDIR/moxie"
  70  
  71  echo "installed to $INSTALL_DIR" >&2
  72  echo "binary: $BINDIR/moxie-${VNUM} (symlink: $BINDIR/moxie)" >&2
  73  
  74  echo "rebuilding package cache with new compiler ..." >&2
  75  MOXIEROOT="$INSTALL_DIR" LLVM_GLUE_PATH="$INSTALL_DIR/llvm-glue/libmoxie-llvm-glue.so" \
  76      "$BINDIR/moxie" update --all
  77  
  78  echo "warming stdlib cache ..." >&2
  79  MOXIEROOT="$INSTALL_DIR" LLVM_GLUE_PATH="$INSTALL_DIR/llvm-glue/libmoxie-llvm-glue.so" \
  80      "$INSTALL_DIR/bin/moxie" cache warm
  81  
  82  echo "" >&2
  83  echo "done." >&2
  84  echo "" >&2
  85  echo "add to your shell profile:" >&2
  86  echo "  export PATH=\"$BINDIR:\$PATH\"" >&2
  87  echo "  export MOXIEROOT=\"$INSTALL_DIR\"" >&2
  88