73 lines
1.8 KiB
Bash
73 lines
1.8 KiB
Bash
#!/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 python3; then
|
|
missing+=("python3")
|
|
fi
|
|
if ! need_cmd curl && ! need_cmd wget; then
|
|
missing+=("curl/wget")
|
|
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
|
|
|
|
if ! need_cmd brew; then
|
|
die "Homebrew is required to install dependencies. Install from https://brew.sh/ and re-run."
|
|
fi
|
|
|
|
log "Installing missing dependencies with Homebrew: ${missing[*]}"
|
|
|
|
brew install p7zip python jq wget openjdk@11
|
|
|
|
if ! need_cmd 7z || ! need_cmd python3 || ( ! need_cmd curl && ! need_cmd wget ) || ! need_cmd jq; then
|
|
die "Dependencies are still missing after install attempt. Please install manually."
|
|
fi
|
|
|
|
if ! need_cmd java; then
|
|
brew_prefix="$(brew --prefix)"
|
|
jdk_bin="${brew_prefix}/opt/openjdk@11/bin"
|
|
export_line="export PATH=\"${jdk_bin}:\$PATH\""
|
|
profile=""
|
|
shell_name="$(basename "${SHELL:-}")"
|
|
if [ "$shell_name" = "zsh" ]; then
|
|
profile="${HOME}/.zprofile"
|
|
elif [ "$shell_name" = "bash" ]; then
|
|
profile="${HOME}/.bash_profile"
|
|
else
|
|
profile="${HOME}/.profile"
|
|
fi
|
|
|
|
if [ ! -f "$profile" ] || ! grep -Fq "$export_line" "$profile"; then
|
|
log "Adding OpenJDK 11 to PATH in ${profile}"
|
|
printf '\n%s\n' "$export_line" >> "$profile"
|
|
fi
|
|
|
|
# shellcheck source=/dev/null
|
|
if [ -f "$profile" ]; then
|
|
. "$profile"
|
|
fi
|
|
|
|
if ! need_cmd java; then
|
|
die "Java is still missing after install. Try opening a new terminal or add ${jdk_bin} to your PATH."
|
|
fi
|
|
fi
|
|
|
|
log "Dependencies installed successfully."
|