Skip to content

Instantly share code, notes, and snippets.

@lis186
Last active February 13, 2024 01:36
Show Gist options
  • Save lis186/b25442ab6c2f5a892cf6c6a50a1c4ac8 to your computer and use it in GitHub Desktop.
Save lis186/b25442ab6c2f5a892cf6c6a50a1c4ac8 to your computer and use it in GitHub Desktop.
Automating pkl Installation on macOS with a Shell Script
# Determine the shell being used
if [ -n "$ZSH_VERSION" ]; then
CONFIG_FILE=~/.zshrc
elif [ -n "$BASH_VERSION" ]; then
CONFIG_FILE=~/.bash_profile
else
echo "Unsupported shell."
exit 1
fi
# Create the directory for local binaries if it doesn't exist
mkdir -p ~/.local/bin
# Determine the CPU architecture and set the download URL accordingly
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
DOWNLOAD_URL="https://github.com/apple/pkl/releases/download/0.25.2/pkl-macos-aarch64"
elif [ "$ARCH" = "x86_64" ]; then
DOWNLOAD_URL="https://github.com/apple/pkl/releases/download/0.25.2/pkl-macos-amd64"
else
echo "Unsupported CPU architecture."
exit 1
fi
# Download the pkl binary and set it as executable
curl -L $DOWNLOAD_URL -o ~/.local/bin/pkl
chmod +x ~/.local/bin/pkl
# Append the directory to PATH in the appropriate config file, if not already present
if ! grep -q 'export PATH="$HOME/.local/bin:$PATH"' $CONFIG_FILE; then
echo 'export PATH="$HOME/.local/bin:$PATH"' >> $CONFIG_FILE
echo "Updated $CONFIG_FILE with PATH settings."
else
echo "$CONFIG_FILE already contains the necessary PATH settings."
fi
# Reload the shell configuration
source $CONFIG_FILE
# Validate the installation by checking the version of pkl
~/.local/bin/pkl --version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment