-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·104 lines (88 loc) · 2.68 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·104 lines (88 loc) · 2.68 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -euo pipefail
pm_for_os() {
[[ -f /etc/os-release ]] || { echo "Cannot detect OS: /etc/os-release not found" >&2; return 1; }
# shellcheck source=/dev/null
source /etc/os-release
# just in case, set id as optional
local id="${ID:-}"
id="${id,,}"
# not every OS uses ID_LIKE, must be set as optional.
local id_like="${ID_LIKE:-}"
id_like=" ${id_like,,} "
case "$id" in
debian|ubuntu|linuxmint|pop|elementary|zorin|kali|parrot|raspbian|neon|deepin)
echo apt; return ;;
fedora) echo dnf; return ;;
rhel|centos|rocky|almalinux|ol|scientific|azurelinux|mariner)
echo dnf; return ;;
arch|manjaro|endeavouros|garuda|cachyos)
echo pacman; return ;;
esac
case "$id_like" in
*" debian "*) echo apt; return ;;
*" rhel "*) echo dnf; return ;;
*" fedora "*) echo dnf; return ;;
*" arch "*) echo pacman; return ;;
esac
echo "Unsupported OS: ${PRETTY_NAME:-$ID}" >&2
return 1
}
detect_pm() {
local pm
pm="$(pm_for_os)" || return 1
if ! command -v "$pm" &>/dev/null; then
echo "Expected package manager '$pm' for this OS is not installed." >&2
return 1
fi
echo "$pm"
}
is_rhel_like() {
[[ -f /etc/os-release ]] || return 1
source /etc/os-release
case "${ID:-}" in
rhel|centos|rocky|almalinux|ol|scientific) return 0 ;;
*) return 1 ;;
esac
}
ensure_epel() {
is_rhel_like || return 0
if rpm -q epel-release &>/dev/null; then return 0; fi
echo "Installing EPEL (required for json-devel on RHEL)..."
sudo dnf install -y epel-release
}
install_deps() {
local pm="$1"; shift
local pkgs=("$@")
case "$pm" in
apt)
sudo apt update
sudo apt install -y "${pkgs[@]}"
;;
dnf)
sudo dnf install -y "${pkgs[@]}"
;;
pacman)
sudo pacman -Sy --needed --noconfirm "${pkgs[@]}"
;;
*) echo "Unsupported package manager" >&2; exit 1
;;
esac
}
PM="$(detect_pm)" || exit 1
case "$PM" in
apt) DEPS=(build-essential cmake libboost-program-options-dev nlohmann-json3-dev arp-scan) ;;
dnf) DEPS=(gcc-c++ make cmake boost-devel json-devel arp-scan) ;;
pacman) DEPS=(base-devel cmake boost nlohmann-json arp-scan) ;;
*) echo "Unsupported package manager: $PM" >&2; exit 1 ;;
esac
[[ "$PM" == "dnf" ]] && ensure_epel
install_deps "${PM}" "${DEPS[@]}"
echo -e "\033[32m[OK] Dependencies installed.\033[0m"
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
BUILD_DIR="${BUILD_DIR:-$PROJECT_DIR/build}"
cmake -S "$PROJECT_DIR" -B "$BUILD_DIR"
cmake --build "$BUILD_DIR" -j "$(nproc)"
echo -e "\033[32mBuild Successful.\033[0m"
sudo install -m 755 "$BUILD_DIR/rsc" /usr/local/bin/
echo -e "\033[32mInstalled rsc to /usr/local/bin.\033[0m"