|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | + |
| 5 | +# Load environment variables from .env file |
| 6 | +ENV_FILE="${PWD}/.env" |
| 7 | +touch "${ENV_FILE}" |
| 8 | +export $(grep -v '^#' "${ENV_FILE}" | xargs) |
| 9 | + |
| 10 | + |
| 11 | +raw_arch=$(uname -m) |
| 12 | + |
| 13 | +# Determine the architecture string ("amd64" or "arm64") |
| 14 | +case "$raw_arch" in |
| 15 | + x86_64) |
| 16 | + ARCH="amd64" |
| 17 | + URL=${AMD64_BINARY_URL} |
| 18 | + ;; |
| 19 | + aarch64|arm64) # Match both 'aarch64' and 'arm64' outputs |
| 20 | + ARCH="arm64" |
| 21 | + URL=${ARM64_BINARY_URL} |
| 22 | + ;; |
| 23 | + *) |
| 24 | + echo "Error: Detected architecture '$raw_arch' is not explicitly supported as amd64 or arm64." >&2 |
| 25 | + exit 1 |
| 26 | + ;; |
| 27 | +esac |
| 28 | + |
| 29 | +EXECUTABLE="rops-${ARCH}" |
| 30 | + |
| 31 | +# 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) |
| 36 | + |
| 37 | +echo "Release JSON: ${RELEASE_JSON}" |
| 38 | +# Extract the top-level release name from the JSON file |
| 39 | +TAG=$(echo "${RELEASE_JSON}" | grep -oP '"name":\s*"\K[^"]+' | head -n 1) |
| 40 | + |
| 41 | +if [ -z "${TAG}" ]; then |
| 42 | + echo "Error: Top-level release name not found in the JSON file." >&2 |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | + |
| 47 | +# Extract the asset ID for the given asset name from RELEASE_JSON |
| 48 | +ASSET_ID=$(echo "${RELEASE_JSON}" | grep -oP '"id":\s*\d+|"name":\s*"'${EXECUTABLE}'"' | paste - - | grep "\"name\": \"${EXECUTABLE}\"" | sed -n 's/.*"id":\s*\([0-9]*\).*/\1/p') |
| 49 | + |
| 50 | +if [ -z "${ASSET_ID}" ]; then |
| 51 | + echo "Error: Asset with name '${EXECUTABLE}' not found in the release assets." >&2 |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +INSTALL_DIR="$HOME/bin" |
| 56 | + |
| 57 | +# Create the ~/bin directory if it doesn't exist |
| 58 | +mkdir -p "$INSTALL_DIR" |
| 59 | +EXECUTABLE_PATH="${INSTALL_DIR}/rops" |
| 60 | + |
| 61 | +ASSET_URL="https://api.github.com/repos/quantmind/rops/releases/assets/${ASSET_ID}" |
| 62 | +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} |
| 67 | + |
| 68 | +if [ $? -ne 0 ]; then |
| 69 | + echo "Error: Failed to download the asset '${BINARY_NAME}'." >&2 |
| 70 | + exit 1 |
| 71 | +fi |
| 72 | + |
| 73 | +chmod +x ${EXECUTABLE_PATH} |
| 74 | +echo "Installed ${EXECUTABLE_PATH}" |
| 75 | + |
| 76 | +${EXECUTABLE_PATH} settings |
0 commit comments