#!/bin/sh set -e reset="\033[0m" red="\033[31m" green="\033[32m" yellow="\033[33m" cyan="\033[36m" white="\033[37m" printf "\n$yellow Installing Nitric!$reset\n\n" VERSION=latest # Detect platform if [[ $OSTYPE == "linux"* ]]; then PLATFORM="Linux" elif [[ $OSTYPE == "darwin"* ]]; then PLATFORM="macOS" else printf "$red Sorry, there's no Nitric binary installer available for this platform. Please open request for it at https://github.com/nitrictech/cli/issues.$reset\n" exit 1 fi # Detect architecture MACHINE_TYPE=`uname -m` if [[ $MACHINE_TYPE == "x86_64" ]]; then ARCH='x86_64' elif [[ $MACHINE_TYPE == "arm64" ]]; then ARCH='arm64' else printf "$red Sorry, there's no Nitric installer available for $MACHINE_TYPE architecture. If you'd like one you're welcome to request it at https://github.com/nitrictech/cli/issues.$reset\n" exit 1 fi if [[ $VERSION == "latest" ]]; then LATEST_TAG=`curl -L --silent https://api.github.com/repos/nitrictech/cli/releases/latest 2>&1 | grep 'tag_name' | grep -oE "v[0-9]+\.[0-9]+\.[0-9]+"` VERSION="${LATEST_TAG:1}" fi BINARY_URL=https://github.com/nitrictech/cli/releases/download/v$VERSION/nitric_$VERSION\_$PLATFORM\_$ARCH.tar.gz # Dowload binary BINARIES_DIR_PATH=$HOME/.nitric/bin TAR_PATH=$BINARIES_DIR_PATH/nitric.tar.gz BINARY_PATH=$BINARIES_DIR_PATH/nitric mkdir -p $BINARIES_DIR_PATH printf "$yellow Downloading tarball...$reset\n" curl -L $BINARY_URL | tar -xz --directory $BINARIES_DIR_PATH chmod +x $BINARY_PATH # Add to $PATH SOURCE_STR="# Added by nitric binary installer\nexport PATH=\"\$HOME/.nitric/bin:\$PATH\"\n" add_to_path () { command printf "\n$SOURCE_STR" >> "$1" printf "\n$yellow Added the following to $1:\n\n$SOURCE_STR$reset" } SHELLTYPE="$(basename "/$SHELL")" if [[ $SHELLTYPE = "fish" ]]; then command fish -c 'set -U fish_user_paths $fish_user_paths ~/.nitric/bin' printf "\n$yellow Added ~/.nitric/bin to fish_user_paths universal variable$reset." elif [[ $SHELLTYPE = "zsh" ]]; then SHELL_CONFIG=$HOME/.zshrc if [ ! -r $SHELL_CONFIG ] || (! `grep -q '.nitric/bin' $SHELL_CONFIG`); then add_to_path $SHELL_CONFIG fi else SHELL_CONFIG=$HOME/.bashrc if [ ! -r $SHELL_CONFIG ] || (! `grep -q '.nitric/bin' $SHELL_CONFIG`); then add_to_path $SHELL_CONFIG fi SHELL_CONFIG=$HOME/.bash_profile if [[ -r $SHELL_CONFIG ]]; then if [[ ! $(grep -q '.nitric/bin' $SHELL_CONFIG) ]]; then add_to_path $SHELL_CONFIG fi else SHELL_CONFIG=$HOME/.bash_login if [[ -r $SHELL_CONFIG ]]; then if [[ ! $(grep -q '.nitric/bin' $SHELL_CONFIG) ]]; then add_to_path $SHELL_CONFIG fi else SHELL_CONFIG=$HOME/.profile if [ ! -r $SHELL_CONFIG ] || (! `grep -q '.nitric/bin' $SHELL_CONFIG`); then add_to_path $SHELL_CONFIG fi fi fi fi printf "$green Installed Successfully, run$yellow source $SHELL_CONFIG$green to update PATH or restart your terminal $reset\n" # TODO: Add post install if necessary # $HOME/.nitric/bin/nitric binary-postinstall