#!/bin/sh set -e # Vikasit Code Installer # Usage: curl -fsSL https://vikasit.ai/install | sh # Windows users: run irm https://vikasit.ai/install.ps1 | iex REPO="Vikasit-AI/releases" BINARY="vikasit" # Detect OS and architecture detect_platform() { OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) # Messages here MUST go to stderr. This function is called as # PLATFORM=$(detect_platform), so anything on stdout is captured into the # variable instead of shown — which silently hid the Windows hint below. case "$OS" in linux) OS="linux" ;; darwin) OS="darwin" ;; # Git Bash / MSYS2 / Cygwin report MINGW64_NT-*, MSYS_NT-*, CYGWIN_NT-*. # They can run this script but there is no POSIX build for them; point at # the PowerShell installer, which fetches the native windows-*.zip. mingw*|msys*|cygwin*|windows*) echo "Vikasit Code has a native Windows build; this POSIX installer cannot install it." >&2 echo "" >&2 echo "Run this in PowerShell instead:" >&2 echo "" >&2 echo " irm https://vikasit.ai/install.ps1 | iex" >&2 echo "" >&2 exit 1 ;; *) echo "Unsupported OS: $OS" >&2 echo "Windows users: run irm https://vikasit.ai/install.ps1 | iex" >&2 exit 1 ;; esac case "$ARCH" in x86_64|amd64) ARCH="x64" ;; aarch64|arm64) ARCH="arm64" ;; *) echo "Unsupported architecture: $ARCH" >&2; exit 1 ;; esac # The default x64 build is compiled with AVX2. On a pre-Haswell CPU (roughly # pre-2013) it installs fine and then panics on every run, which reads as a # broken install rather than an unsupported CPU. Fall back to the -baseline # build, which exists for those machines. arm64 is unaffected. if [ "$ARCH" = "x64" ]; then HAS_AVX2="" if [ "$OS" = "linux" ] && [ -r /proc/cpuinfo ]; then HAS_AVX2=$(grep -m1 -o ' avx2' /proc/cpuinfo 2>/dev/null || true) elif [ "$OS" = "darwin" ]; then HAS_AVX2=$(sysctl -n machdep.cpu.leaf7_features 2>/dev/null | grep -o 'AVX2' || true) fi # Only downgrade when the probe ran AND reported no AVX2. If the probe # itself could not run, assume AVX2 so modern machines are unaffected. if [ -z "$HAS_AVX2" ] && { [ -r /proc/cpuinfo ] || [ "$OS" = "darwin" ]; }; then ARCH="x64-baseline" echo "CPU has no AVX2 - using the baseline build." >&2 fi fi echo "${OS}-${ARCH}" } # Get latest version from GitHub (robust parse: tolerant of spacing/order) get_latest_version() { curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" \ | grep '"tag_name"' \ | head -n 1 \ | sed -E 's/.*"tag_name"[[:space:]]*:[[:space:]]*"v?([^"]+)".*/\1/' } PLATFORM=$(detect_platform) VERSION=$(get_latest_version) if [ -z "$VERSION" ]; then echo "Failed to fetch latest version from https://api.github.com/repos/$REPO/releases/latest" exit 1 fi echo "Installing Vikasit Code v$VERSION for $PLATFORM..." # Determine file extension case "$PLATFORM" in linux-*) EXT="tar.gz" ;; darwin-*) EXT="zip" ;; esac URL="https://github.com/$REPO/releases/download/v$VERSION/vikasit-code-$PLATFORM.$EXT" INSTALL_DIR="$HOME/.vikasit/bin" TMP_DIR=$(mktemp -d) echo "Downloading from $URL..." if ! curl -fSL "$URL" -o "$TMP_DIR/vikasit.$EXT"; then echo "" echo "ERROR: Failed to download release asset (it may not exist for this version/platform)." echo " Expected asset: vikasit-code-$PLATFORM.$EXT" echo " URL: $URL" echo " Check available downloads at https://github.com/$REPO/releases/tag/v$VERSION" rm -rf "$TMP_DIR" exit 1 fi echo "Extracting..." cd "$TMP_DIR" case "$EXT" in tar.gz) tar xzf "vikasit.$EXT" ;; zip) unzip -q "vikasit.$EXT" ;; esac echo "Installing to $INSTALL_DIR..." mkdir -p "$INSTALL_DIR" mv "$BINARY" "$INSTALL_DIR/$BINARY" chmod +x "$INSTALL_DIR/$BINARY" # Ensure install dir is on PATH so `vikasit` resolves and self-update works # without sudo (the updater re-runs this installer into the same user dir). case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) SHELL_RC="$HOME/.profile" [ -n "$ZSH_VERSION" ] && SHELL_RC="$HOME/.zshrc" [ -n "$BASH_VERSION" ] && SHELL_RC="$HOME/.bashrc" if ! grep -qs ".vikasit/bin" "$SHELL_RC"; then printf '\nexport PATH="%s:$PATH"\n' "$INSTALL_DIR" >> "$SHELL_RC" fi echo "Added $INSTALL_DIR to PATH in $SHELL_RC. Restart your shell or run: export PATH=\"$INSTALL_DIR:\$PATH\"" ;; esac # Cleanup rm -rf "$TMP_DIR" echo "" echo "Vikasit Code v$VERSION installed successfully!" echo "" echo "Run 'vikasit' to get started."