-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·75 lines (64 loc) · 2.57 KB
/
setup.sh
File metadata and controls
executable file
·75 lines (64 loc) · 2.57 KB
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
75
#!/usr/bin/env bash
# Ensures required host packages are installed before building.
# Called automatically by ./bazel on every invocation (cheap if already satisfied).
#
# To add a requirement, append to REQUIRED_PACKAGES:
# "package_name:OS:arch"
# OS — Linux | Darwin | *
# arch — arm64 | aarch64 | x86_64 | *
set -euo pipefail
OS="$(uname -s)"
ARCH="$(uname -m)"
# ── Package requirements ─────────────────────────────────────────────────────
REQUIRED_PACKAGES=(
"libxml2-dev:Linux:arm64"
"curl:Linux:*"
)
# ── Helpers ──────────────────────────────────────────────────────────────────
detect_pkg_manager() {
if command -v apt-get &>/dev/null; then echo "apt"
elif command -v dnf &>/dev/null; then echo "dnf"
elif command -v yum &>/dev/null; then echo "yum"
elif command -v brew &>/dev/null; then echo "brew"
else echo "unknown"
fi
}
is_installed() {
local pkg="$1" mgr="$2"
case "${mgr}" in
apt) dpkg-query -W -f='${Status}' "${pkg}" 2>/dev/null \
| grep -q "install ok installed" ;;
dnf|yum) rpm -q "${pkg}" &>/dev/null ;;
brew) brew list --formula "${pkg}" &>/dev/null 2>&1 ;;
*) return 1 ;;
esac
}
install_pkg() {
local pkg="$1" mgr="$2"
echo "[setup] Installing missing package: ${pkg}" >&2
case "${mgr}" in
apt) apt update && apt install -y "${pkg}" ;;
dnf) dnf install -y "${pkg}" ;;
yum) yum install -y "${pkg}" ;;
brew) brew install "${pkg}" ;;
*) echo "ERROR: No supported package manager found to install '${pkg}'" >&2; exit 1 ;;
esac
}
arch_matches() {
local req="$1"
case "${req}" in
"*") return 0 ;;
arm64|aarch64) [[ "${ARCH}" == "arm64" || "${ARCH}" == "aarch64" ]] ;;
*) [[ "${ARCH}" == "${req}" ]] ;;
esac
}
# ── Main ─────────────────────────────────────────────────────────────────────
PKG_MGR="$(detect_pkg_manager)"
for entry in "${REQUIRED_PACKAGES[@]}"; do
IFS=':' read -r pkg req_os req_arch <<< "${entry}"
[[ "${req_os}" != "*" && "${OS}" != "${req_os}" ]] && continue
arch_matches "${req_arch}" || continue
if ! is_installed "${pkg}" "${PKG_MGR}"; then
install_pkg "${pkg}" "${PKG_MGR}"
fi
done