#!/usr/bin/env bash INSTALL_DIR="$HOME/.hipo/bin" RELEASE_API_URL="https://api.github.com/repos/devhipo/hipo/releases/latest" echo "Fetching the latest release from $RELEASE_API_URL..." LATEST_TAG=$(curl -s $RELEASE_API_URL | perl -nle 'print $& while m{"tag_name": "\K(.*)(?=")}g') if [ -z "$LATEST_TAG" ]; then echo "Failed to fetch the latest release tag. Exiting." exit 1 fi echo "Latest release tag: $LATEST_TAG" # Determine the OS OS="" case "$(uname -s)" in Darwin) OS="macos" ;; Linux) OS="linux" ;; *) echo "Unsupported OS. Exiting." exit 1 ;; esac case "$(uname -m)" in x86_64) ARCH="x64" ;; arm64) ARCH="arm64" ;; aarch64) ARCH="arm64" ;; *) echo "Unsupported architecture: $ARCH. Exiting." exit 1 ;; esac # Construct the download URL for the specific file FILE_NAME="hipo-$OS-$ARCH-$LATEST_TAG" DOWNLOAD_URL="https://github.com/devhipo/hipo/releases/download/$LATEST_TAG/$FILE_NAME" echo "Downloading binary from $DOWNLOAD_URL..." curl -s -L "$DOWNLOAD_URL" -o "/tmp/$FILE_NAME" if [ ! $? ]; then echo "Failed to download the file. Exiting." exit 1 fi mkdir -p "$INSTALL_DIR" # Move the downloaded file to the home directory echo "Installing the executable to $INSTALL_DIR..." mv "/tmp/$FILE_NAME" "$INSTALL_DIR/hipo" if [ ! $? ]; then echo "Failed to install the executable. Exiting." exit 1 fi chmod +x "$INSTALL_DIR/hipo" # Add the installation directory to the PATH in .bashrc or .zshrc SHELL_RC="" if [[ "$SHELL" == *bash ]]; then SHELL_RC="$HOME/.bashrc" elif [[ "$SHELL" == *zsh ]]; then SHELL_RC="$HOME/.zshrc" else cat <> "$SHELL_RC" export PATH="$INSTALL_DIR:\$PATH" EOF echo "Path successfully updated. Please restart your terminal or run 'source $SHELL_RC' to apply the changes." else echo "$INSTALL_DIR is already in PATH in $SHELL_RC." fi echo "Installation complete. hipo is installed in $INSTALL_DIR."