This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Edgar Gomes <talktoedgar@gmail.com> Co-authored-by: Skylar Brown <skylar.brown@kurtosistech.com>
- Loading branch information
Showing
2 changed files
with
135 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,88 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# Install Kardinal CLI - supports bash, zsh, fish and assumes you have curl procps installed | ||
|
||
# Function to handle errors | ||
handle_error() { | ||
echo "Ops! Failed to setup integration with your shell. Please add the following lines to | ||
your shell configuration manually (changes may not be persistent) | ||
export PATH=\$PATH:$BIN_FOLDER | ||
source <($BIN_FOLDER/$BINARY_NAME completion $PARENT_SHELL)" | ||
exit 1 | ||
} | ||
|
||
# Rest of your script goes here | ||
REPO="kurtosis-tech/kardinal" | ||
BINARY_NAME="kardinal" | ||
|
||
OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
ARCH=$(uname -m) | ||
|
||
if [[ "$ARCH" == "x86_64" ]]; then | ||
ARCH="amd64" | ||
elif [[ "$ARCH" == "arm64" ]]; then | ||
ARCH="arm64" | ||
elif [[ "$ARCH" == "aarch64" ]]; then | ||
ARCH="arm64" | ||
fi | ||
case "$ARCH" in | ||
x86_64) ARCH="amd64" ;; | ||
arm64 | aarch64) ARCH="arm64" ;; | ||
esac | ||
|
||
BIN_FOLDER="$HOME/.local/bin" | ||
mkdir -p $BIN_FOLDER | ||
mkdir -p "$BIN_FOLDER" | ||
|
||
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | ||
WAS_INTALLED_BEFORE=0 | ||
if [ -f "$BIN_FOLDER/$BINARY_NAME" ]; then | ||
WAS_INTALLED_BEFORE=1 | ||
fi | ||
|
||
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | ||
echo "Downloading $BINARY_NAME $LATEST_RELEASE for $OS $ARCH..." | ||
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$LATEST_RELEASE/${BINARY_NAME}-${OS}-${ARCH}" | ||
curl -L $DOWNLOAD_URL -o /$BIN_FOLDER/$BINARY_NAME | ||
chmod +x $BIN_FOLDER/$BINARY_NAME | ||
|
||
USER_SHELL=$(basename $SHELL) | ||
echo "Detected shell: $USER_SHELL" | ||
|
||
handle_error() { | ||
local exit_code=$? | ||
echo "Ops! Failed to setup integration with your $USER_SHELL shell. Please add the following lines to | ||
your shell configuration manually (changes may not be persistent) | ||
export PATH=\$PATH:$BIN_FOLDER | ||
source <($BIN_FOLDER/$BINARY_NAME completion $USER_SHELL)" | ||
exit $exit_code | ||
} | ||
curl -L "$DOWNLOAD_URL" -o "$BIN_FOLDER/$BINARY_NAME" | ||
chmod +x "$BIN_FOLDER/$BINARY_NAME" | ||
|
||
trap 'handle_error' ERR | ||
PARENT_SHELL=$(ps -o comm= -p $PPID) | ||
echo "Detected parent shell: $PARENT_SHELL" | ||
|
||
if [ -f $BIN_FOLDER/$BINARY_NAME ]; then | ||
if [ $USER_SHELL == 'bash' ]; then | ||
echo "export PATH=\$PATH:$BIN_FOLDER" >>~/.bashrc | ||
echo "source <($BIN_FOLDER/$BINARY_NAME completion bash)" >>~/.bashrc | ||
source ~/.bashrc | ||
fi | ||
|
||
if [ $USER_SHELL == 'zsh' ]; then | ||
echo "export PATH=\$PATH:$BIN_FOLDER" >>~/.zshrc | ||
echo "source <($BIN_FOLDER/$BINARY_NAME completion zsh)" >>~/.bashrc | ||
source ~/.zshrc | ||
fi | ||
|
||
if [ $USER_SHELL == 'fish' ]; then | ||
echo "set -gx PATH \$PATH $BIN_FOLDER" >>~/.config/fish/config.fish | ||
echo "source <($BIN_FOLDER/$BINARY_NAME completion fish)" >>~/.bashrc | ||
source ~/.config/fish/config.fish | ||
if [ -f "$BIN_FOLDER/$BINARY_NAME" ]; then | ||
if [ $WAS_INTALLED_BEFORE -eq 0 ]; then | ||
case "$PARENT_SHELL" in | ||
-bash | bash) | ||
CONFIG_FILE="$HOME/.bashrc" | ||
if ! echo "# Kardinal CLI config" >>"$CONFIG_FILE"; then | ||
handle_error | ||
fi | ||
echo "export PATH=\$PATH:$BIN_FOLDER" >>"$CONFIG_FILE" | ||
echo "source <($BIN_FOLDER/$BINARY_NAME completion bash)" >>"$CONFIG_FILE" | ||
;; | ||
-zsh | zsh) | ||
CONFIG_FILE="$HOME/.zshrc" | ||
if ! echo "# Kardinal CLI config" >>"$CONFIG_FILE"; then | ||
handle_error | ||
fi | ||
echo "export PATH=\$PATH:$BIN_FOLDER" >>"$CONFIG_FILE" | ||
echo "autoload -U +X compinit && compinit" >>"$CONFIG_FILE" | ||
echo "source <($BIN_FOLDER/$BINARY_NAME completion zsh)" >>"$CONFIG_FILE" | ||
;; | ||
-fish | fish) | ||
CONFIG_FILE="$HOME/.config/fish/config.fish" | ||
if ! echo "# Kardinal CLI config" >>"$CONFIG_FILE"; then | ||
handle_error | ||
fi | ||
echo "set -gx PATH \$PATH $BIN_FOLDER" >>"$CONFIG_FILE" | ||
echo "source ($BIN_FOLDER/$BINARY_NAME completion fish | psub)" >>"$CONFIG_FILE" | ||
;; | ||
*) | ||
echo "Unrecognized shell: $PARENT_SHELL" | ||
handle_error | ||
;; | ||
esac | ||
echo "$BINARY_NAME has been installed successfully!" | ||
echo "Run the following command to load Kardinal in the current shell (new shell will already load it):" | ||
echo "" | ||
echo "> source $CONFIG_FILE" | ||
echo "" | ||
else | ||
echo "Kardinal was installed before, just updated it." | ||
echo "" | ||
fi | ||
else | ||
echo "Failed to install $BINARY_NAME. Please try again." | ||
echo "" | ||
exit 1 | ||
fi | ||
|
||
echo "$BINARY_NAME has been installed successfully!" |