74 lines
1.7 KiB
Bash
74 lines
1.7 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
validate_root_usage() {
|
|
if [[ "$(id -u)" -ne 0 ]]; then
|
|
fail "$(t root_required)"
|
|
fi
|
|
}
|
|
|
|
validate_core_support() {
|
|
local supported_cores="pmmp,paper,purpur,velocity,powernukkitx,nethergamesmc"
|
|
local supported_os="ubuntu,debian"
|
|
local planned_os="arch,fedora,rocky,almalinux"
|
|
|
|
case "$CORE" in
|
|
pmmp|paper|purpur|velocity|powernukkitx|nethergamesmc)
|
|
;;
|
|
*)
|
|
fail "$(t unsupported_core "$CORE" "$supported_cores" "${SCRIPT_DIR}/manifests/cores.json")"
|
|
;;
|
|
esac
|
|
|
|
case "$OS_ID" in
|
|
ubuntu|debian)
|
|
return 0
|
|
;;
|
|
arch|fedora|rocky|almalinux)
|
|
warn "$(t os_coreplanned "$OS_ID" "${SCRIPT_DIR}/manifests/os-support.json")"
|
|
;;
|
|
*)
|
|
fail "$(t unsupported_os "$OS_ID" "$supported_os" "$planned_os" "${SCRIPT_DIR}/manifests/os-support.json")"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
validate_eula() {
|
|
if ! is_java_core "$CORE"; then
|
|
return 0
|
|
fi
|
|
|
|
if [[ "${ACCEPT_EULA,,}" != "yes" ]]; then
|
|
fail "$(t eula_denied)"
|
|
fi
|
|
}
|
|
|
|
validate_port() {
|
|
local port="$1"
|
|
local protocol="$2"
|
|
|
|
if ! command -v ss >/dev/null 2>&1; then
|
|
if command -v lsof >/dev/null 2>&1; then
|
|
if [[ "$protocol" == "tcp" ]]; then
|
|
if lsof -iTCP:"$port" -sTCP:LISTEN -n -P >/dev/null 2>&1; then
|
|
fail "$(t tcp_port_in_use "$port")"
|
|
fi
|
|
else
|
|
if lsof -iUDP:"$port" -n -P >/dev/null 2>&1; then
|
|
fail "$(t udp_port_in_use "$port")"
|
|
fi
|
|
fi
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
if [[ "$protocol" == "tcp" ]]; then
|
|
if ss -ltn | awk '{print $4}' | grep -q ":${port}$"; then
|
|
fail "$(t tcp_port_in_use "$port")"
|
|
fi
|
|
else
|
|
if ss -lun | awk '{print $5}' | grep -q ":${port}$"; then
|
|
fail "$(t udp_port_in_use "$port")"
|
|
fi
|
|
fi
|
|
}
|