|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -e |
3 | 3 |
|
4 | | - |
5 | | -# Load environment variables from .env file |
| 4 | +# Install rops binary from GitHub releases |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# Local: ./install-rops |
| 8 | +# Remote: curl -sSL https://raw.githubusercontent.com/quantmind/rops/main/dev/install-rops | GITHUB_TOKEN=your_token bash |
| 9 | +# |
| 10 | +# Requirements: |
| 11 | +# - GITHUB_TOKEN environment variable (for accessing private repos or avoiding rate limits) |
| 12 | + |
| 13 | +# Load environment variables from .env file if it exists (for local development) |
6 | 14 | ENV_FILE="${PWD}/.env" |
7 | | -touch "${ENV_FILE}" |
8 | | -export $(grep -v '^#' "${ENV_FILE}" | xargs) |
| 15 | +if [ -f "${ENV_FILE}" ]; then |
| 16 | + export $(grep -v '^#' "${ENV_FILE}" | xargs) |
| 17 | +fi |
9 | 18 |
|
10 | 19 |
|
11 | 20 | raw_arch=$(uname -m) |
|
28 | 37 |
|
29 | 38 | EXECUTABLE="rops-${ARCH}" |
30 | 39 |
|
| 40 | +# Prepare authentication header if GITHUB_TOKEN is set |
| 41 | +AUTH_HEADER="" |
| 42 | +if [ -n "${GITHUB_TOKEN}" ]; then |
| 43 | + AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" |
| 44 | +fi |
| 45 | + |
31 | 46 | # Fetch the release JSON from GitHub API |
32 | | -RELEASE_JSON=$(curl -s \ |
33 | | - -H "Accept: application/vnd.github+json" \ |
34 | | - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ |
35 | | - https://api.github.com/repos/quantmind/rops/releases/latest) |
| 47 | +if [ -n "${AUTH_HEADER}" ]; then |
| 48 | + RELEASE_JSON=$(curl -s \ |
| 49 | + -H "Accept: application/vnd.github+json" \ |
| 50 | + -H "${AUTH_HEADER}" \ |
| 51 | + https://api.github.com/repos/quantmind/rops/releases/latest) |
| 52 | +else |
| 53 | + RELEASE_JSON=$(curl -s \ |
| 54 | + -H "Accept: application/vnd.github+json" \ |
| 55 | + https://api.github.com/repos/quantmind/rops/releases/latest) |
| 56 | +fi |
36 | 57 |
|
37 | 58 | echo "Release JSON: ${RELEASE_JSON}" |
38 | 59 | # Extract the top-level release name from the JSON file |
@@ -60,13 +81,19 @@ EXECUTABLE_PATH="${INSTALL_DIR}/rops" |
60 | 81 |
|
61 | 82 | ASSET_URL="https://api.github.com/repos/quantmind/rops/releases/assets/${ASSET_ID}" |
62 | 83 | echo "Download rops executable from ${ASSET_URL}" |
63 | | -curl -L \ |
64 | | - -H "Accept: application/octet-stream" \ |
65 | | - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ |
66 | | - ${ASSET_URL} -o ${EXECUTABLE_PATH} |
| 84 | +if [ -n "${AUTH_HEADER}" ]; then |
| 85 | + curl -L \ |
| 86 | + -H "Accept: application/octet-stream" \ |
| 87 | + -H "${AUTH_HEADER}" \ |
| 88 | + ${ASSET_URL} -o ${EXECUTABLE_PATH} |
| 89 | +else |
| 90 | + curl -L \ |
| 91 | + -H "Accept: application/octet-stream" \ |
| 92 | + ${ASSET_URL} -o ${EXECUTABLE_PATH} |
| 93 | +fi |
67 | 94 |
|
68 | 95 | if [ $? -ne 0 ]; then |
69 | | - echo "Error: Failed to download the asset '${BINARY_NAME}'." >&2 |
| 96 | + echo "Error: Failed to download the asset '${EXECUTABLE}'." >&2 |
70 | 97 | exit 1 |
71 | 98 | fi |
72 | 99 |
|
|
0 commit comments