File size: 2,513 Bytes
fd357f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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" # override with NATS_VERSION
  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" # override with DRAGONFLY_VERSION
  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" # override with JANUSGRAPH_VERSION
  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 "$@"