#!/usr/bin/env bash ## ## ## ## ## ## ## : ========================= : Getting Started : ========================= # This script allows you to install the latest version of the # Pinbase CLI tool "pinbase" by running the following command # : curl -sL dist.pinbase.io | bash # : ======================== : Upgrading : ======================== # To upgrade an existing Pinbase install, run the following command # : curl -sL dist.pinbase.io | upgrade=true bash # : ======================== : Uninstalling : ======================== # You can remove Pinbase by running the following command # : curl -sL dist.pinbase.io | uninstall=true bash # : ======================== : Source Code : ======================== # Check if Pinbase is already installed echo "🚧 Checking for existing installs..." EXISITNG_INSTALL=$(which pinbase) # Unistall Pinbase. This is check first so we don't install anything # unnecessarily if [ "$uninstall" = "true" ]; then # Check an installation actually exists by checking the length of # the $EXISITNG_INSTALL string is not zero if [ ! -z "$EXISITNG_INSTALL" ]; then # Finds the binary using the `which` command and then removes it echo "😢 Uninstalling binary..." sudo rm $(which pinbase) # Remove the Pinbase config directory echo "😢 Removing configs..." rm -rf ~/.pinbase # We're sad to see you go... echo "😢 All done... Hope to see you again soon!" echo "" echo "Care to tell us why you left? Feel free to head over to our Discord!" exit 0 else # No install found, cannot proceed echo "🚧 No existing Pinbase installation found..." echo "🚧 Cannot uninstall!" exit 0 fi fi # The user is about to be promted for their password, this explains # why it's needed echo "🚧 Preparing install directory..." echo "💡 Needs sudo to create directory and install binary (in /usr/local/bin)" echo "💡 You can verify the source code at https://dist.pinbase.io" # This is the default install location for user programs on Unix # based systems (i.e. Linux and MacOS) INSTALL_DIR="/usr/local/bin" # Ensure the install directory actually exists (won't do anything # if it already does) sudo mkdir -p "$INSTALL_DIR" # If length of the $EXISITNG_INSTALL string is not zero, then do not # proceed with installation unless we're upgrading if [ ! -z "$EXISITNG_INSTALL" ]; then VERSION=$(pinbase -v) if [ ! "$upgrade" = "true" ]; then echo "🚧 You already have $VERSION installed!" echo "🚧 If you want to upgrade, run `curl -sL dist.pinbase.io | upgrade=true bash`" exit 0 else echo "🚧 You currently have $VERSION installed" echo "🚧 Attempting to upgrade Pinbase..." fi fi echo "🚧 Getting machine type and architecture..." # Get the OS and architecture in lowercase format UNAME_OS=$(uname -s | tr '[:upper:]' '[:lower:]') UNAME_ARCH=$(uname -m | tr '[:upper:]' '[:lower:]') # Check if the OS is supported against this list case "$UNAME_OS" in "linux") OS="linux";; "darwin") OS="darwin";; esac # Check if the architecture is supported case "$UNAME_ARCH" in "x86_64") ARCH="amd64";; "i386") ARCH="386";; "arm64") ARCH="arm64";; "armv8"*) ARCH="arm64";; "armv7"*) ARCH="arm";; "armv6"*) ARCH="arm";; esac # If we cannot get both the OS and architecture, then exit if [[ -z "$OS" || -z "$ARCH" ]]; then echo "❌ Was unable to determine machine type and architecture." echo "❌ Pinbase CLI may not support your machine yet..." echo "❌ Please report this on the community Discord!" exit 0 fi # Create the download URL URL="https://dist.pinbase.io/bin/latest/$OS/$ARCH/pinbase" echo "🚧 Downloading the Pinbase CLI binary..." # Download the binary directly to the install directory sudo curl -o "$INSTALL_DIR/pinbase" -L --progress-bar $URL echo "🚧 Download complete!" # Mark the binary as executable echo "🚧 Setting permissions..." sudo chmod +rx "$INSTALL_DIR/pinbase" # Test the install by getting the version VERSION=$($INSTALL_DIR/pinbase -v) # If the length of the $VERSION string is zero, then the installation # failed if [ -z "$VERSION" ]; then echo "❌ Something went wrong in the download..." echo "❌ Please report this on the community Discord" exit 1 fi # Check the installation directory is actually in the user's path if [[ ! ":$PATH:" == *":$INSTALL_DIR:"* ]]; then echo "🚧 The install directory ($INSTALL_DIR) is not in your PATH..." echo "🚧 Add the following to your ~/bash_profile or ~/.profile to add it, then restart your terminal" echo "" echo "PATH=\$PATH:$INSTALL_DIR" echo "" echo "🚧 After that, the installation *should* be complete!" fi # All done! Display message and exit out of the script echo "🚧 $VERSION is installed!" echo "✅ All done! Enjoy using Pinbase!" exit 0