| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| require_root() { |
| if [[ "$EUID" -ne 0 ]]; then |
| echo "❌ Please run as root (sudo)" |
| exit 1 |
| fi |
| } |
|
|
| detect_os() { |
| if command -v apt-get >/dev/null; then echo apt; return; fi |
| if command -v dnf >/dev/null; then echo dnf; return; fi |
| if command -v yum >/dev/null; then echo yum; return; fi |
| if command -v pacman >/dev/null; then echo pacman; return; fi |
| echo unknown |
| } |
|
|
| install_java() { |
| local pm=$(detect_os) |
| case "$pm" in |
| apt) apt-get update && apt-get install -y openjdk-17-jre-headless curl tar ;; |
| dnf) dnf install -y java-17-openjdk-headless curl tar ;; |
| yum) yum install -y java-17-openjdk-headless curl tar ;; |
| pacman) pacman -Sy --noconfirm jre17-openjdk curl tar ;; |
| *) echo "⚠️ Install Java 17 manually" ;; |
| esac |
| } |
|
|
| install_nats() { |
| local ver="v2.10.17" |
| ver="${NATS_VERSION:-$ver}" |
| local url="https://github.com/nats-io/nats-server/releases/download/${ver}/nats-server-${ver}-linux-amd64.tar.gz" |
| echo "Installing nats-server ${ver}..." |
| curl -fsSL "$url" -o /tmp/nats.tar.gz |
| tar -xzf /tmp/nats.tar.gz -C /tmp |
| install -m 0755 /tmp/nats-server-*/nats-server /usr/local/bin/nats-server |
| echo "✅ nats-server installed: $(/usr/local/bin/nats-server --version | head -n1)" |
| } |
|
|
| install_dragonfly() { |
| local ver="v1.22.0" |
| ver="${DRAGONFLY_VERSION:-$ver}" |
| local url="https://github.com/dragonflydb/dragonfly/releases/download/${ver}/dragonfly-${ver}-linux-x86_64.tar.gz" |
| echo "Installing dragonfly ${ver}..." |
| curl -fsSL "$url" -o /tmp/dragonfly.tar.gz |
| tar -xzf /tmp/dragonfly.tar.gz -C /tmp |
| install -m 0755 /tmp/dragonfly /usr/local/bin/dragonfly || install -m 0755 /tmp/dragonfly*/dragonfly /usr/local/bin/dragonfly |
| echo "✅ dragonfly installed: $(/usr/local/bin/dragonfly --version || echo installed)" |
| } |
|
|
| install_janusgraph() { |
| local ver="0.6.3" |
| ver="${JANUSGRAPH_VERSION:-$ver}" |
| local url="https://github.com/JanusGraph/janusgraph/releases/download/v${ver}/janusgraph-${ver}.zip" |
| echo "Installing JanusGraph ${ver} to /opt/janusgraph..." |
| mkdir -p /opt |
| curl -fsSL "$url" -o /tmp/janusgraph.zip |
| cd /opt && unzip -q /tmp/janusgraph.zip && ln -snf "/opt/janusgraph-${ver}" /opt/janusgraph |
| echo "✅ JanusGraph installed at /opt/janusgraph" |
| } |
|
|
| main() { |
| require_root |
| install_java |
| install_nats |
| install_dragonfly |
| install_janusgraph |
| echo "\nAll prerequisites installed." |
| } |
|
|
| main "$@" |
|
|
|
|