#!/bin/sh set -e printf "Installing Chalk...\n" base_url=${2:-https://api.chalk.ai} os=$(uname -s) arch=$(uname -m) version=${1:-latest} url="$base_url/v1/install/$os/$arch/$version" chalk_cli_install="${CHALK_INSTALL:-$HOME/.chalk}" bin_dir="$chalk_cli_install/bin" exe="$bin_dir/chalk-install" simexe="$bin_dir/chalk" if [ ! -d "$bin_dir" ]; then mkdir -p "$bin_dir" fi printf "Downloading binary for %s %s..." "$os" "$arch" CODE=$(curl -sSL -w '%{http_code}' -o "$exe" "$url") if [ "$CODE" "=" "200" ]; then printf " Done!\n\n" else echo "\nDownloading Chalk returned HTTP code $CODE" exit 1 fi { chmod +x "$exe" } || { printf "Could not set script to executable. Please run chmod +x on your install" } CHALK_VERSION=$("$exe" version --tag-only) new_location="$bin_dir/chalk-$CHALK_VERSION" mv "$exe" "$new_location" ln -sf "$new_location" "$simexe" "$simexe" version printf "\nChalk was installed successfully to %s\n" "$new_location" if command -v chalk >/dev/null; then printf "Run 'chalk --help' to get started.\n\n" printf "You may need to open a new terminal window for these changes to take effect.\n" else case $SHELL in /bin/zsh) shell_profile=".zshrc" ;; /usr/bin/zsh) shell_profile=".zshrc" ;; *) shell_profile=".bash_profile" ;; esac CHALK_COMPLETION="export CHALK_INSTALL=\"$chalk_cli_install\"\nexport PATH=\"\$CHALK_INSTALL/bin:\$PATH\"" echo "$CHALK_COMPLETION" >> "$HOME"/"$shell_profile" echo "Added Chalk to path in \$HOME/$shell_profile" echo " export CHALK_INSTALL=\"$chalk_cli_install\"" printf " export PATH=\"\$CHALK_INSTALL/bin:\$PATH\"\n" echo "Open a new window or run 'source $HOME/$shell_profile' to start using Chalk!" fi