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

Install script #101

Merged
merged 4 commits into from
Dec 8, 2023
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ More details on various output formats and aggregators (including examples) can

## Installation

### Manual
### Bash Script

This script downloads the latest version from github, and installs it to `~/.local/bin` (`/usr/bin` if *root*).

```sh
curl -sfL https://rare.zdyn.net/install.sh | bash
```

### Manual (Prebuilt Binary)

Download appropriate binary or package from [Releases](https://github.com/zix99/rare/releases)

Expand Down
10 changes: 9 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ Take a look at [examples](usage/examples.md) to see more of what *rare* does.

I will leave it up to the user as to which they find suitable to use for their situation. Generally, if you know what *rare* is getting as an input, the pcre version is perfectly safe and can be much faster.

### Manual
### Bash Script

This script downloads the latest version from github, and installs it to `~/.local/bin` (`/usr/bin` if *root*).

```sh
curl -sfL https://rare.zdyn.net/install.sh | bash
```

### Manual (Prebuilt Binary)

Download appropriate binary or package from [Releases](https://github.com/zix99/rare/releases)

Expand Down
84 changes: 84 additions & 0 deletions docs/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
set -e

REPO=zix99/rare
LATEST_TAG_URL="https://api.github.com/repos/${REPO}/releases/latest"
RELEASES_URL="https://github.com/${REPO}/releases"
FILE_BASENAME="rare"

# Get latest version tag
echo "Fetching latest version..."
LATEST=$( curl -sf "$LATEST_TAG_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' )

if [[ -z $LATEST ]]; then
echo "Unable to get version" >&2
exit 1
fi
echo " Version: ${LATEST}"

# Temp dir and cleanup
TMP_DIR="$(mktemp -d)"
trap "rm -rf \"$TMP_DIR\"" EXIT INT TERM

# Detect version
OS="$(uname -s)"
ARCH="$(uname -m)"

TAR_SUFFIX="tar.gz"
INSTALL_DIR="$HOME/.local/bin"
case $OS in
aarch64)
OS=arm64
;;
MSYS_NT*)
OS=Windows
TAR_SUFFIX="zip"
;;
Darwin)
INSTALL_DIR="$HOME/bin"
;;
esac

# Download
TAR_FILENAME="${FILE_BASENAME}_${LATEST}_${OS}_${ARCH}.${TAR_SUFFIX}"
URL="$RELEASES_URL/download/$LATEST/$TAR_FILENAME"

cd $TMP_DIR
echo "Downloading $TAR_FILENAME to $TMP_DIR..." >&2
curl -sfLO $URL
tar xzf $TAR_FILENAME

if [[ ! -f rare ]]; then
echo "Something went wrong, download did not include binary" >&2
exit 1
fi

# Install
if [[ $USER == "root" ]]; then
INSTALL_DIR="/usr/bin"
echo "Installing as root to $INSTALL_DIR..." >&2
chown root:root rare*
else
echo "Installing to user home $INSTALL_DIR ..." >&2
mkdir -p $INSTALL_DIR
fi

if [[ ! $PATH =~ $INSTALL_DIR ]]; then
echo "WARNING: Installation path not in \$PATH environment" >&2
fi

chmod +x rare
mv rare $INSTALL_DIR
echo "Installed rare to $INSTALL_DIR" >&2

if [[ -f rare-pcre ]]; then
chmod +x rare-pcre
mv rare-pcre $INSTALL_DIR
echo "Installed rare-pcre to $INSTALL_DIR" >&2
fi

# Install man page if able
if [[ $USER == "root" && -f rare.1.gz ]]; then
cp rare.1.gz /usr/share/man/man1/
echo "Installed man page" >&2
fi
Loading