Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ echo "hello" | xpbc
curl -fsSL https://raw.githubusercontent.com/chigichan24/xpbc/main/Scripts/install.sh | bash
```

The script downloads the latest universal binary (arm64 + x86_64) and prompts you for the install directory (default: `~/.local/bin`).
To install to a custom directory:

```sh
curl -fsSL https://raw.githubusercontent.com/chigichan24/xpbc/main/Scripts/install.sh | bash -s -- /your/custom/path
```

The default install directory is `~/.local/bin`.

### From source

Expand Down
49 changes: 12 additions & 37 deletions Scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,25 @@ set -euo pipefail
REPO="chigichan24/xpbc"
ASSET_NAME="xpbc-macos.artifactbundle.zip"
ASSET_URL="https://github.com/$REPO/releases/latest/download/$ASSET_NAME"
DEFAULT_INSTALL_DIR="$HOME/.local/bin"
TMPDIR_INSTALL=$(mktemp -d)
INSTALL_DIR="${1:-$HOME/.local/bin}"

cleanup() {
rm -rf "$TMPDIR_INSTALL"
}
trap cleanup EXIT
# Download zip file
echo "Downloading latest xpbc..."
curl -sL -o "$ASSET_NAME" "$ASSET_URL"
unzip -qo "$ASSET_NAME" -d extracted_files
rm "$ASSET_NAME"

echo "xpbc installer"
echo ""

# Read from /dev/tty so this works even when piped via curl | bash
printf "Install directory [%s]: " "$DEFAULT_INSTALL_DIR"
read -r INSTALL_DIR < /dev/tty || true
INSTALL_DIR="${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}"

# Expand ~ to $HOME
INSTALL_DIR="${INSTALL_DIR/#\~/$HOME}"

echo ""
echo "Downloading latest release..."
curl -sL -o "$TMPDIR_INSTALL/$ASSET_NAME" "$ASSET_URL"

echo "Extracting..."
unzip -qo "$TMPDIR_INSTALL/$ASSET_NAME" -d "$TMPDIR_INSTALL"

VERSION=$(ls "$TMPDIR_INSTALL/xpbc.artifactbundle" | sed -n 's/^xpbc-\([^-]*\)-macos$/\1/p' | head -n 1)
VERSION=$(ls ./extracted_files/xpbc.artifactbundle | sed -n 's/^xpbc-\([^-]*\)-macos$/\1/p' | head -n 1)
if [ -z "$VERSION" ]; then
echo "Error: could not determine version from artifact bundle."
echo "Error: version not found in the artifact bundle."
rm -rf extracted_files
exit 1
fi

mkdir -p "$INSTALL_DIR"
cp -f "$TMPDIR_INSTALL/xpbc.artifactbundle/xpbc-$VERSION-macos/bin/xpbc" "$INSTALL_DIR/xpbc"
cp -f "./extracted_files/xpbc.artifactbundle/xpbc-$VERSION-macos/bin/xpbc" "$INSTALL_DIR/xpbc"
chmod +x "$INSTALL_DIR/xpbc"
rm -rf extracted_files

echo ""
echo "Installed xpbc $VERSION to $INSTALL_DIR/xpbc"

# Check if install dir is in PATH
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
echo ""
echo "Note: $INSTALL_DIR is not in your PATH."
echo "Add the following to your shell profile (~/.zshrc or ~/.bashrc):"
echo ""
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
fi
echo "Please make sure $INSTALL_DIR is in your \$PATH"