#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' log() { echo "[$(date +'%F %T')] $*"; } die() { log "ERROR: $*"; exit 1; } need_cmd() { command -v "$1" >/dev/null 2>&1; } missing=() if ! need_cmd 7z; then missing+=("7z") fi if ! need_cmd curl && ! need_cmd wget; then missing+=("curl/wget") fi if ! need_cmd rsync; then missing+=("rsync") fi if ! need_cmd jq; then missing+=("jq") fi if ! need_cmd java; then missing+=("java") fi if [ "${#missing[@]}" -eq 0 ]; then log "All dependencies already satisfied." exit 0 fi log "Missing dependencies detected: ${missing[*]}" SUDO="" if [ "$(id -u)" -ne 0 ]; then if need_cmd sudo; then SUDO="sudo" else die "Root privileges are required to install dependencies (sudo not found)." fi fi if need_cmd apt-get; then ${SUDO} apt-get update ${SUDO} apt-get install -y curl wget jq rsync p7zip-full python3 log "Installing Java runtime (trying OpenJDK 11, 17, then default-jre)..." if ! ${SUDO} apt-get install -y openjdk-11-jre-headless; then if ! ${SUDO} apt-get install -y openjdk-17-jre-headless; then if ! ${SUDO} apt-get install -y default-jre-headless; then ${SUDO} apt-get install -y default-jre fi fi fi elif need_cmd apt; then ${SUDO} apt update ${SUDO} apt install -y curl wget jq rsync p7zip-full python3 log "Installing Java runtime (trying OpenJDK 11, 17, then default-jre)..." if ! ${SUDO} apt install -y openjdk-11-jre-headless; then if ! ${SUDO} apt install -y openjdk-17-jre-headless; then if ! ${SUDO} apt install -y default-jre-headless; then ${SUDO} apt install -y default-jre fi fi fi elif need_cmd dnf; then ${SUDO} dnf install -y curl wget jq rsync p7zip p7zip-plugins python3 java-11-openjdk-headless elif need_cmd yum; then ${SUDO} yum install -y curl wget jq rsync p7zip p7zip-plugins python3 java-11-openjdk-headless elif need_cmd pacman; then ${SUDO} pacman -Sy --noconfirm curl wget jq rsync p7zip python jre11-openjdk elif need_cmd apk; then ${SUDO} apk add --no-cache curl wget jq rsync p7zip python3 openjdk11-jre elif need_cmd zypper; then ${SUDO} zypper install -y curl wget jq rsync p7zip python3 java-11-openjdk else die "No supported package manager found. Please install curl/wget, 7z, rsync, jq, and Java manually." fi if ! need_cmd 7z || ( ! need_cmd curl && ! need_cmd wget ) || ! need_cmd rsync || ! need_cmd jq || ! need_cmd java; then die "Dependencies are still missing after install attempt. Please install manually." fi log "Dependencies installed successfully."