Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/install via script #28

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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 @@ -16,7 +16,13 @@ gruyere makes use of the wonderful [Charm](https://github.com/charmbracelet) lib
- [Log](https://github.com/charmbracelet/log)

## Installation
You can install the appropriate binary for your operating system by visiting the [Releases page](https://github.com/savannahostrowski/gruyere/releases).
Get `gruyere` by running the following command:

- MacOS / Linux:

```bash
curl -L link/install.sh | sh
```

## Contributing
Contributions are welcome! To get started, check out the [contributing guidelines](CONTRIBUTING.md).
Expand Down
58 changes: 58 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env sh

set -e

# Determine OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case $ARCH in
x86_64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
i386|i686)
ARCH="386"
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac

# Check for version argument
# Otherwise, set latest release version
if [ -z "$VERSION" ]; then
VERSION=$(curl -s "https://api.github.com/repos/savannahostrowski/gruyere/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([0-9.]+)".*/\1/')
fi

# Construct download URL
DOWNLOAD_URL="https://github.com/savannahostrowski/gruyere/releases/download/v${VERSION}/gruyere_${VERSION}_${OS}_${ARCH}.tar.gz"

# Create temporary directory
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT

# Download and extract
echo "Downloading gruyere ${VERSION} for ${OS} ${ARCH}..."
curl -L -s "$DOWNLOAD_URL" | tar -xz -C "$TMP_DIR"

# Check if directory is writable by the current user
# If not, use sudo to install
INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin}
if [ ! -w "$INSTALL_DIR" ]; then
echo "Installing gruyere to $INSTALL_DIR..."
sudo mkdir -p "$INSTALL_DIR"
sudo mv "$TMP_DIR/gruyere" "$INSTALL_DIR/"
else
echo "Installing gruyere to $INSTALL_DIR..."
mkdir -p "$INSTALL_DIR"
mv "$TMP_DIR/gruyere" "$INSTALL_DIR/"
fi

echo "gruyere ${VERSION} has been installed successfully!"
echo "Be sure that $INSTALL_DIR is in your PATH:"
printf "\n\texport PATH=\$PATH:%s\n\n" "$INSTALL_DIR"
echo "You can now use the 'gruyere' command."