-
Notifications
You must be signed in to change notification settings - Fork 169
Prepare for curl|bash installation.
#128
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c3fc933
.goreleaser.yaml: Remove completions.
toothbrush 8db13ce
.goreleaser: Give archives entire_* names.
toothbrush 6225733
install.sh: Initial commit.
toothbrush 85e8c8e
Fix trap quoting.
toothbrush 1a578a1
Don't try fancy sudo tricks when installing.
toothbrush 16116f0
If we are curl|bash, no need to check for curl.
toothbrush a29692b
Just curl.
toothbrush 08ab642
Error if we couldn't find checksum.
toothbrush 0ec3c61
Ignore file.FOO entries.
toothbrush dfa2369
'entire version' is a verb not a flag
toothbrush 7f02dc3
We can mkdir if we install to homedir...
toothbrush e1feec6
Output is easier on the eyes.
toothbrush b7a27ac
Check for curl.
toothbrush 4cfc8e1
Update scripts/install.sh
toothbrush 32177bc
Sure
toothbrush 46bddd7
case-sensitive checksums matching.
toothbrush e52bd47
We don't accept ENTIRE_VERSION=... any more.
toothbrush fa99c07
Missing checksums is an error
toothbrush 8d3daf4
Safer backslash escapes
toothbrush 38da10c
Remove mentions of ENTIRE_VERSION
toothbrush c974846
More sensible example.
toothbrush e9afd9c
Allow GITHUB_TOKEN, to circumvent public rate limits.
toothbrush 9649225
Verify checksums - straighten out logic.
toothbrush dbea510
Remove self-explanatory comments.
toothbrush 4e32cf5
Nicer error output (\n not interpolated)
toothbrush b76bea9
unnecessarily defensive.
toothbrush 6dd7b5b
Remove linebreak.
toothbrush e0ae19d
Make it local :shrug:
toothbrush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| #!/bin/bash | ||
| # Entire CLI installer | ||
| # Usage: curl -fsSL https://entire.io/install.sh | bash | ||
| # | ||
| # Environment variables: | ||
| # ENTIRE_INSTALL_DIR - Override install directory | ||
| # GITHUB_TOKEN - GitHub API token to avoid rate limiting | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| GITHUB_REPO="entireio/cli" | ||
| BINARY_NAME="entire" | ||
| DEFAULT_INSTALL_DIR="$HOME/.local/bin" | ||
|
|
||
| # Colors (disabled in non-interactive mode) | ||
| if [[ -t 1 ]]; then | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[0;33m' | ||
| BLUE='\033[0;34m' | ||
| BOLD='\033[1m' | ||
| NC='\033[0m' # No Color | ||
| else | ||
| RED='' | ||
| GREEN='' | ||
| YELLOW='' | ||
| BLUE='' | ||
| BOLD='' | ||
| NC='' | ||
| fi | ||
|
|
||
| info() { | ||
| printf '%b%s%b\n' "${BLUE}==>${NC} ${BOLD}" "$1" "${NC}" | ||
| } | ||
|
|
||
| success() { | ||
| printf '%b%s%b\n' "${GREEN}==>${NC} ${BOLD}" "$1" "${NC}" | ||
| } | ||
|
|
||
| warn() { | ||
| printf '%b %s\n' "${YELLOW}Warning:${NC}" "$1" | ||
| } | ||
|
|
||
| error() { | ||
| printf '%b %s\n' "${RED}Error:${NC}" "$1" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| show_help() { | ||
| cat << EOF | ||
| Entire CLI Installer | ||
|
|
||
| Usage: | ||
| curl -fsSL https://entire.io/install.sh | bash | ||
|
|
||
| Environment Variables: | ||
| ENTIRE_INSTALL_DIR Override install directory (default: $HOME/.local/bin) | ||
| GITHUB_TOKEN GitHub API token to avoid rate limiting (optional) | ||
|
|
||
| Examples: | ||
| # Install latest version | ||
| curl -fsSL https://entire.io/install.sh | bash | ||
|
|
||
| # Install to custom directory | ||
| curl -fsSL https://entire.io/install.sh | ENTIRE_INSTALL_DIR=/usr/local/bin bash | ||
| EOF | ||
| exit 0 | ||
| } | ||
|
|
||
| detect_os() { | ||
| local os | ||
| os="$(uname -s | tr '[:upper:]' '[:lower:]')" | ||
| case "$os" in | ||
| darwin) | ||
| echo "darwin" | ||
| ;; | ||
| linux) | ||
| echo "linux" | ||
| ;; | ||
| *) | ||
| error "Unsupported operating system: $os" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| detect_arch() { | ||
| local arch | ||
| arch="$(uname -m)" | ||
| case "$arch" in | ||
| x86_64|amd64) | ||
| echo "amd64" | ||
| ;; | ||
| arm64|aarch64) | ||
| echo "arm64" | ||
| ;; | ||
| *) | ||
| error "Unsupported architecture: $arch" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| get_latest_version() { | ||
| local url="https://api.github.com/repos/${GITHUB_REPO}/releases/latest" | ||
| local version | ||
| local curl_opts=(-fsSL) | ||
| if [[ -n "${GITHUB_TOKEN:-}" ]]; then | ||
| curl_opts+=(-H "Authorization: Bearer ${GITHUB_TOKEN}") | ||
| fi | ||
| version=$(curl "${curl_opts[@]}" "$url" 2>/dev/null | grep '"tag_name"' | sed -E 's/.*"tag_name": *"v?([^"]+)".*/\1/') | ||
|
|
||
| if [[ -z "$version" ]]; then | ||
| error "Failed to fetch latest version from GitHub. Please check your internet connection." | ||
| fi | ||
|
|
||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "$version" | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| download_file() { | ||
| local url="$1" | ||
| local output="$2" | ||
|
|
||
| curl -fsSL "$url" -o "$output" | ||
| } | ||
|
|
||
| verify_checksum() { | ||
| local file="$1" | ||
| local expected_checksum="$2" | ||
| local actual_checksum | ||
|
|
||
| if command -v sha256sum &> /dev/null; then | ||
| actual_checksum=$(sha256sum "$file" | awk '{print $1}') | ||
| elif command -v shasum &> /dev/null; then | ||
| actual_checksum=$(shasum -a 256 "$file" | awk '{print $1}') | ||
| else | ||
| warn "No checksum tool found (sha256sum or shasum). Skipping verification." | ||
| return 0 | ||
| fi | ||
|
|
||
| if [[ "$actual_checksum" != "$expected_checksum" ]]; then | ||
| error "Checksum verification failed! Expected: $expected_checksum, actual: $actual_checksum" | ||
| fi | ||
| } | ||
|
|
||
| main() { | ||
| for arg in "$@"; do | ||
| if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then | ||
| show_help | ||
| fi | ||
| done | ||
|
|
||
| if ! command -v curl &> /dev/null; then | ||
| error "curl is required but not installed. Please install curl and try again." | ||
| fi | ||
|
|
||
| info "Installing Entire CLI..." | ||
|
|
||
| # Detect platform | ||
| local os arch | ||
| os=$(detect_os) | ||
| arch=$(detect_arch) | ||
| info "Detected platform: ${os}/${arch}" | ||
|
|
||
| info "Fetching latest version..." | ||
| local version | ||
| version=$(get_latest_version) | ||
| # Strip leading 'v' if present | ||
| version="${version#v}" | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| info "Installing version: ${version}" | ||
|
|
||
| # Construct download URL | ||
| local archive_name="${BINARY_NAME}_${os}_${arch}.tar.gz" | ||
| local download_url="https://github.com/${GITHUB_REPO}/releases/download/v${version}/${archive_name}" | ||
| local checksums_url="https://github.com/${GITHUB_REPO}/releases/download/v${version}/checksums.txt" | ||
|
|
||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| local tmp_dir | ||
| tmp_dir=$(mktemp -d) | ||
| trap 'rm -rf "$tmp_dir"' EXIT | ||
|
|
||
| # Download archive | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| local archive_path="${tmp_dir}/${archive_name}" | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| info "Downloading ${archive_name}..." | ||
| if ! download_file "$download_url" "$archive_path"; then | ||
| error "Failed to download from ${download_url}. Please check that the version exists and try again." | ||
| fi | ||
|
|
||
| # Download and verify checksums | ||
| info "Downloading checksums..." | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| local checksums_path="${tmp_dir}/checksums.txt" | ||
| if ! download_file "$checksums_url" "$checksums_path"; then | ||
| error "Failed to download checksums from ${checksums_url}" | ||
| fi | ||
|
|
||
| info "Verifying checksum..." | ||
| local expected_checksum | ||
| expected_checksum=$(grep -iE "${archive_name}\$" "$checksums_path" | awk '{print $1}' || true) | ||
| if [[ -z "$expected_checksum" ]]; then | ||
| error "Checksum for ${archive_name} not found in checksums.txt" | ||
| fi | ||
| verify_checksum "$archive_path" "$expected_checksum" | ||
| success "Checksum verified" | ||
|
|
||
| info "Extracting..." | ||
| tar -xzf "$archive_path" -C "$tmp_dir" | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| local install_dir="${ENTIRE_INSTALL_DIR:-$DEFAULT_INSTALL_DIR}" | ||
| local binary_path="${tmp_dir}/${BINARY_NAME}" | ||
|
|
||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| chmod +x "$binary_path" | ||
|
|
||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| info "Installing to ${install_dir}..." | ||
| local install_path="${install_dir}/${BINARY_NAME}" | ||
|
|
||
| mkdir -p "${install_dir}" | ||
|
|
||
| if [[ ! -w "$install_dir" ]]; then | ||
| error "Cannot write to ${install_dir}. Run with sudo or set ENTIRE_INSTALL_DIR to a writable location." | ||
| fi | ||
| mv "$binary_path" "$install_path" | ||
|
|
||
| # Verify installation | ||
| if "$install_path" version &> /dev/null; then | ||
| success "Entire CLI installed successfully!" | ||
| echo "" | ||
| echo "Run 'entire --help' to get started." | ||
toothbrush marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else | ||
| error "Installation completed but the binary failed to execute. Please check the installation." | ||
| fi | ||
|
|
||
| # Check if the installed binary is the one that will be found in PATH | ||
| local path_binary | ||
| path_binary=$(command -v "$BINARY_NAME" 2>/dev/null || true) | ||
| if [[ -n "$path_binary" && "$path_binary" != "$install_path" ]]; then | ||
| echo "" | ||
| echo -e "${YELLOW}!${NC} ${BOLD}WARNING: PATH conflict detected${NC}" | ||
| echo -e "${YELLOW}!${NC}" | ||
| echo -e "${YELLOW}!${NC} Installed to: ${install_path}" | ||
| echo -e "${YELLOW}!${NC} But '${BINARY_NAME}' resolves to: ${path_binary}" | ||
| echo -e "${YELLOW}!${NC}" | ||
| echo -e "${YELLOW}!${NC} Your PATH may have another version earlier. To fix:" | ||
| echo -e "${YELLOW}!${NC} 1. Remove the old binary: rm ${path_binary}" | ||
| echo -e "${YELLOW}!${NC} 2. Or adjust your PATH to prioritize ${install_dir}" | ||
| echo "" | ||
| elif [[ -z "$path_binary" ]]; then | ||
| echo "" | ||
| echo -e "${YELLOW}!${NC} ${BOLD}WARNING: '${BINARY_NAME}' not found in PATH${NC}" | ||
| echo -e "${YELLOW}!${NC}" | ||
| echo -e "${YELLOW}!${NC} Installed to: ${install_path}" | ||
| echo -e "${YELLOW}!${NC} But this directory is not in your PATH." | ||
| echo -e "${YELLOW}!${NC}" | ||
| echo -e "${YELLOW}!${NC} Add to your shell config (.bashrc, .zshrc, etc.):" | ||
| echo -e "${YELLOW}!${NC} export PATH=\"\$PATH:${install_dir}\"" | ||
| echo "" | ||
| fi | ||
| } | ||
|
|
||
| main "$@" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.