#!/bin/bash

VERSION="latest"
sudo pip uninstall -y runflare > /dev/null 2>&1
sudo pip3 uninstall -y runflare > /dev/null 2>&1
if [ ! -z "$1" ]; then
    VERSION="$1"
fi
OS_TYPE=$(uname -s)
case "$OS_TYPE" in
    Darwin)
        BINARY_URL="https://get.runflare.com/$VERSION/runflare-darwin-amd64"
        ;;
    Linux)
        BINARY_URL="https://get.runflare.com/$VERSION/runflare-linux-amd64"
        ;;
    *)
        echo "Unsupported OS type: $OS_TYPE. Please use a 'darwin' or 'linux' based system."
        exit 1
        ;;
esac
INSTALL_PATH="/usr/local/bin"
curl -L -o runflare $BINARY_URL
sudo mv runflare $INSTALL_PATH/runflare
sudo chmod +x $INSTALL_PATH/runflare
if command -v runflare version &> /dev/null
then
    echo "Installation successful! You can run the program by typing 'runflare'."
else
    echo "Something went wrong. Please check the installation steps."
fi
