**Refactor OS detection and normalize Manjaro to Arch**
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
Some checks failed
Mark stable commit / test-unit (push) Has been cancelled
Mark stable commit / test-integration (push) Has been cancelled
Mark stable commit / test-env-virtual (push) Has been cancelled
Mark stable commit / test-env-nix (push) Has been cancelled
Mark stable commit / test-e2e (push) Has been cancelled
Mark stable commit / test-virgin-user (push) Has been cancelled
Mark stable commit / test-virgin-root (push) Has been cancelled
Mark stable commit / mark-stable (push) Has been cancelled
* Centralize OS detection and normalization in a dedicated resolver module * Treat Manjaro consistently as Arch across dependencies and package install * Remove duplicated OS logic and legacy lib.sh * Rename installation entrypoint to init.sh and update Makefile accordingly https://chatgpt.com/share/693c7b50-3be0-800f-8aeb-daf3ee929ea3
This commit is contained in:
2
Makefile
2
Makefile
@@ -36,7 +36,7 @@ export TEST_PATTERN
|
|||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
install:
|
install:
|
||||||
@echo "Building and installing distro-native package-manager for this system..."
|
@echo "Building and installing distro-native package-manager for this system..."
|
||||||
@bash scripts/installation/main.sh
|
@bash scripts/installation/init.sh
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# PKGMGR setup
|
# PKGMGR setup
|
||||||
|
|||||||
@@ -3,22 +3,19 @@ set -euo pipefail
|
|||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck disable=SC1091
|
||||||
source "${SCRIPT_DIR}/lib.sh"
|
source "${SCRIPT_DIR}/os_resolver.sh"
|
||||||
|
|
||||||
OS_ID="$(detect_os_id)"
|
OS_ID="$(osr_get_os_id)"
|
||||||
|
|
||||||
echo "[run-dependencies] Detected OS: ${OS_ID}"
|
echo "[run-dependencies] Detected OS: ${OS_ID}"
|
||||||
|
|
||||||
case "${OS_ID}" in
|
if ! osr_is_supported "${OS_ID}"; then
|
||||||
arch|debian|ubuntu|fedora|centos)
|
echo "[run-dependencies] Unsupported OS: ${OS_ID}"
|
||||||
DEP_SCRIPT="${SCRIPT_DIR}/${OS_ID}/dependencies.sh"
|
exit 1
|
||||||
;;
|
fi
|
||||||
*)
|
|
||||||
echo "[run-dependencies] Unsupported OS: ${OS_ID}"
|
DEP_SCRIPT="$(osr_script_path_for "${SCRIPT_DIR}" "${OS_ID}" "dependencies")"
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [[ ! -f "${DEP_SCRIPT}" ]]; then
|
if [[ ! -f "${DEP_SCRIPT}" ]]; then
|
||||||
echo "[run-dependencies] Dependency script not found: ${DEP_SCRIPT}"
|
echo "[run-dependencies] Dependency script not found: ${DEP_SCRIPT}"
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
detect_os_id() {
|
|
||||||
if [[ -f /etc/os-release ]]; then
|
|
||||||
# shellcheck disable=SC1091
|
|
||||||
. /etc/os-release
|
|
||||||
echo "${ID:-unknown}"
|
|
||||||
else
|
|
||||||
echo "unknown"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
82
scripts/installation/os_resolver.sh
Normal file
82
scripts/installation/os_resolver.sh
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# OsResolver (bash "class-style" module)
|
||||||
|
# Centralizes OS detection + normalization + supported checks + script paths.
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
osr_detect_raw_id() {
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
. /etc/os-release
|
||||||
|
echo "${ID:-unknown}"
|
||||||
|
else
|
||||||
|
echo "unknown"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
osr_detect_id_like() {
|
||||||
|
if [[ -f /etc/os-release ]]; then
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
. /etc/os-release
|
||||||
|
echo "${ID_LIKE:-}"
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
osr_normalize_id() {
|
||||||
|
local raw="${1:-unknown}"
|
||||||
|
local like="${2:-}"
|
||||||
|
|
||||||
|
# Explicit mapping first (your bugfix: manjaro -> arch everywhere)
|
||||||
|
case "${raw}" in
|
||||||
|
manjaro) echo "arch"; return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Keep direct IDs when they are already supported
|
||||||
|
case "${raw}" in
|
||||||
|
arch|debian|ubuntu|fedora|centos) echo "${raw}"; return 0 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Fallback mapping via ID_LIKE for better portability
|
||||||
|
# Example: many Arch derivatives expose ID_LIKE="arch"
|
||||||
|
if [[ " ${like} " == *" arch "* ]]; then
|
||||||
|
echo "arch"; return 0
|
||||||
|
fi
|
||||||
|
if [[ " ${like} " == *" debian "* ]]; then
|
||||||
|
echo "debian"; return 0
|
||||||
|
fi
|
||||||
|
if [[ " ${like} " == *" fedora "* ]]; then
|
||||||
|
echo "fedora"; return 0
|
||||||
|
fi
|
||||||
|
if [[ " ${like} " == *" rhel "* || " ${like} " == *" centos "* ]]; then
|
||||||
|
echo "centos"; return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${raw}"
|
||||||
|
}
|
||||||
|
|
||||||
|
osr_get_os_id() {
|
||||||
|
local raw like
|
||||||
|
raw="$(osr_detect_raw_id)"
|
||||||
|
like="$(osr_detect_id_like)"
|
||||||
|
osr_normalize_id "${raw}" "${like}"
|
||||||
|
}
|
||||||
|
|
||||||
|
osr_is_supported() {
|
||||||
|
local id="${1:-unknown}"
|
||||||
|
case "${id}" in
|
||||||
|
arch|debian|ubuntu|fedora|centos) return 0 ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
osr_script_path_for() {
|
||||||
|
local script_dir="${1:?script_dir required}"
|
||||||
|
local os_id="${2:?os_id required}"
|
||||||
|
local kind="${3:?kind required}" # "dependencies" or "package"
|
||||||
|
|
||||||
|
echo "${script_dir}/${os_id}/${kind}.sh"
|
||||||
|
}
|
||||||
@@ -3,28 +3,19 @@ set -euo pipefail
|
|||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck disable=SC1091
|
||||||
source "${SCRIPT_DIR}/lib.sh"
|
source "${SCRIPT_DIR}/os_resolver.sh"
|
||||||
|
|
||||||
OS_ID="$(detect_os_id)"
|
OS_ID="$(osr_get_os_id)"
|
||||||
|
|
||||||
# Map Manjaro to Arch
|
|
||||||
if [[ "${OS_ID}" == "manjaro" ]]; then
|
|
||||||
echo "[package] Mapping OS 'manjaro' → 'arch'"
|
|
||||||
OS_ID="arch"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[package] Detected OS: ${OS_ID}"
|
echo "[package] Detected OS: ${OS_ID}"
|
||||||
|
|
||||||
case "${OS_ID}" in
|
if ! osr_is_supported "${OS_ID}"; then
|
||||||
arch|debian|ubuntu|fedora|centos)
|
echo "[package] Unsupported OS: ${OS_ID}"
|
||||||
PKG_SCRIPT="${SCRIPT_DIR}/${OS_ID}/package.sh"
|
exit 1
|
||||||
;;
|
fi
|
||||||
*)
|
|
||||||
echo "[package] Unsupported OS: ${OS_ID}"
|
PKG_SCRIPT="$(osr_script_path_for "${SCRIPT_DIR}" "${OS_ID}" "package")"
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [[ ! -f "${PKG_SCRIPT}" ]]; then
|
if [[ ! -f "${PKG_SCRIPT}" ]]; then
|
||||||
echo "[package] Package script not found: ${PKG_SCRIPT}"
|
echo "[package] Package script not found: ${PKG_SCRIPT}"
|
||||||
|
|||||||
Reference in New Issue
Block a user