|
| 1 | +#!/bin/sh |
| 2 | +# Cybermonkey – Hera Installer |
| 3 | +# Usage: curl -fsSL https://get.cybermonkey.sh/hera | sh |
| 4 | +# |
| 5 | +# Hera is a Chrome extension for authentication security monitoring — |
| 6 | +# detects vulnerabilities in OAuth2, OIDC, SAML, SCIM, and WebAuthn flows. |
| 7 | +# |
| 8 | +# Human Technology — https://cybermonkey.sh |
| 9 | + |
| 10 | +set -eu |
| 11 | + |
| 12 | +REPO="hera" |
| 13 | +DESCRIPTION="Auth Security Chrome Extension" |
| 14 | +GITEA="https://gitea.cybermonkey.sh/cybermonkey" |
| 15 | +BRANCH="main" |
| 16 | +INSTALL_DIR="${CYBERMONKEY_HOME:-$HOME/.cybermonkey}/${REPO}" |
| 17 | + |
| 18 | +if [ -t 1 ]; then |
| 19 | + RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[0;33m' |
| 20 | + BLUE='\033[0;34m'; BOLD='\033[1m'; RESET='\033[0m' |
| 21 | +else |
| 22 | + RED=''; GREEN=''; YELLOW=''; BLUE=''; BOLD=''; RESET='' |
| 23 | +fi |
| 24 | + |
| 25 | +info() { printf "${BLUE}ℹ${RESET} %s\n" "$*"; } |
| 26 | +ok() { printf "${GREEN}✔${RESET} %s\n" "$*"; } |
| 27 | +warn() { printf "${YELLOW}⚠${RESET} %s\n" "$*"; } |
| 28 | +err() { printf "${RED}✖${RESET} %s\n" "$*" >&2; } |
| 29 | +fatal() { err "$@"; exit 1; } |
| 30 | + |
| 31 | +banner() { |
| 32 | + printf "\n${BOLD}" |
| 33 | + cat <<'ART' |
| 34 | + ╔═══════════════════════════════════════════╗ |
| 35 | + ║ 🐵 Cybermonkey · Hera Installer ║ |
| 36 | + ║ Human Technology ║ |
| 37 | + ╚═══════════════════════════════════════════╝ |
| 38 | +ART |
| 39 | + printf "${RESET}\n" |
| 40 | +} |
| 41 | + |
| 42 | +need_cmd() { command -v "$1" >/dev/null 2>&1 || fatal "'$1' is required but not found."; } |
| 43 | + |
| 44 | +fetch() { |
| 45 | + if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" |
| 46 | + elif command -v wget >/dev/null 2>&1; then wget -qO "$2" "$1" |
| 47 | + else fatal "Neither curl nor wget found."; fi |
| 48 | +} |
| 49 | + |
| 50 | +preflight() { |
| 51 | + info "Checking prerequisites…" |
| 52 | + need_cmd git |
| 53 | + # Node.js needed for building |
| 54 | + if command -v node >/dev/null 2>&1; then |
| 55 | + NODE_VER=$(node --version) |
| 56 | + ok "Node.js found: ${NODE_VER}" |
| 57 | + else |
| 58 | + warn "Node.js not found — you'll need it to build the extension" |
| 59 | + fi |
| 60 | + |
| 61 | + if command -v npm >/dev/null 2>&1; then |
| 62 | + ok "npm found" |
| 63 | + elif command -v yarn >/dev/null 2>&1; then |
| 64 | + ok "yarn found" |
| 65 | + else |
| 66 | + warn "npm/yarn not found — needed for dependency installation" |
| 67 | + fi |
| 68 | +} |
| 69 | + |
| 70 | +install() { |
| 71 | + info "Installing ${DESCRIPTION} to ${INSTALL_DIR}…" |
| 72 | + |
| 73 | + if [ -d "${INSTALL_DIR}/.git" ]; then |
| 74 | + info "Existing installation found — pulling latest…" |
| 75 | + (cd "$INSTALL_DIR" && git pull origin "$BRANCH") || warn "Pull failed — continuing with existing version" |
| 76 | + else |
| 77 | + mkdir -p "$(dirname "$INSTALL_DIR")" |
| 78 | + info "Cloning repository…" |
| 79 | + git clone --depth 1 -b "$BRANCH" "${GITEA}/${REPO}.git" "$INSTALL_DIR" 2>/dev/null \ |
| 80 | + || git clone --depth 1 -b "$BRANCH" "https://gitea.cybermonkey.sh/cybermonkey/${REPO}.git" "$INSTALL_DIR" |
| 81 | + fi |
| 82 | + ok "Source code downloaded to ${INSTALL_DIR}" |
| 83 | + |
| 84 | + # Install dependencies and build |
| 85 | + if [ -f "${INSTALL_DIR}/package.json" ]; then |
| 86 | + info "Installing npm dependencies…" |
| 87 | + (cd "$INSTALL_DIR" && npm install --no-fund --no-audit 2>/dev/null) \ |
| 88 | + && ok "Dependencies installed" \ |
| 89 | + || warn "npm install failed — you may need to install manually" |
| 90 | + |
| 91 | + # Build extension if build script exists |
| 92 | + if grep -q '"build"' "${INSTALL_DIR}/package.json" 2>/dev/null; then |
| 93 | + info "Building extension…" |
| 94 | + (cd "$INSTALL_DIR" && npm run build 2>/dev/null) \ |
| 95 | + && ok "Extension built" \ |
| 96 | + || warn "Build failed — you may need to build manually" |
| 97 | + fi |
| 98 | + fi |
| 99 | + |
| 100 | + ok "${DESCRIPTION} installed to ${INSTALL_DIR}" |
| 101 | +} |
| 102 | + |
| 103 | +post_install() { |
| 104 | + # Detect build output directory |
| 105 | + DIST_DIR="${INSTALL_DIR}/dist" |
| 106 | + if [ ! -d "$DIST_DIR" ]; then |
| 107 | + DIST_DIR="${INSTALL_DIR}/build" |
| 108 | + fi |
| 109 | + if [ ! -d "$DIST_DIR" ]; then |
| 110 | + DIST_DIR="$INSTALL_DIR" |
| 111 | + fi |
| 112 | + |
| 113 | + printf "\n${BOLD}Next steps — Load as unpacked Chrome extension:${RESET}\n" |
| 114 | + printf " 1. Open Chrome and navigate to:\n" |
| 115 | + printf " ${BLUE}chrome://extensions/${RESET}\n" |
| 116 | + printf " 2. Enable ${BOLD}Developer mode${RESET} (top-right toggle)\n" |
| 117 | + printf " 3. Click ${BOLD}Load unpacked${RESET}\n" |
| 118 | + printf " 4. Select this folder:\n" |
| 119 | + printf " ${GREEN}%s${RESET}\n" "$DIST_DIR" |
| 120 | + printf " 5. Pin the extension from the toolbar\n\n" |
| 121 | + printf " To update later:\n" |
| 122 | + printf " ${YELLOW}cd %s && git pull && npm run build${RESET}\n" "$INSTALL_DIR" |
| 123 | + printf " Then click ↻ Reload on chrome://extensions/\n\n" |
| 124 | + printf " Docs: ${BLUE}${GITEA}/${REPO}${RESET}\n\n" |
| 125 | +} |
| 126 | + |
| 127 | +main() { |
| 128 | + banner |
| 129 | + preflight |
| 130 | + install |
| 131 | + post_install |
| 132 | + ok "Done! 🐵" |
| 133 | +} |
| 134 | + |
| 135 | +main "$@" |
0 commit comments