diff --git a/README.md b/README.md index 2c4ccf0..7f84cd9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Scripts/install.sh b/Scripts/install.sh index d65f82e..5bb38ea 100755 --- a/Scripts/install.sh +++ b/Scripts/install.sh @@ -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"