Refactor container build and installation pipeline to use configurable Makefile parameters (e.g. DISTROS, base images) and propagate them through all build, install, and test scripts
This commit is contained in:
54
scripts/installation/arch/aur-builder-setup.sh
Executable file
54
scripts/installation/arch/aur-builder-setup.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# aur-builder-setup.sh
|
||||
#
|
||||
# Setup helper for an 'aur_builder' user and yay on Arch-based
|
||||
# systems. Intended for host usage and can also be used in
|
||||
# containers if desired.
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo "[aur-builder-setup] Checking for pacman..."
|
||||
if ! command -v pacman >/dev/null 2>&1; then
|
||||
echo "[aur-builder-setup] pacman not found – this is not an Arch-based system. Skipping."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "${EUID:-0}" -ne 0 ]]; then
|
||||
ROOT_CMD="sudo"
|
||||
else
|
||||
ROOT_CMD=""
|
||||
fi
|
||||
|
||||
echo "[aur-builder-setup] Installing base-devel, git, sudo..."
|
||||
${ROOT_CMD} pacman -Syu --noconfirm
|
||||
${ROOT_CMD} pacman -S --needed --noconfirm base-devel git sudo
|
||||
|
||||
echo "[aur-builder-setup] Ensuring aur_builder group/user..."
|
||||
if ! getent group aur_builder >/dev/null 2>&1; then
|
||||
${ROOT_CMD} groupadd -r aur_builder
|
||||
fi
|
||||
|
||||
if ! id -u aur_builder >/dev/null 2>&1; then
|
||||
${ROOT_CMD} useradd -m -r -g aur_builder -s /bin/bash aur_builder
|
||||
fi
|
||||
|
||||
echo "[aur-builder-setup] Configuring sudoers for aur_builder..."
|
||||
${ROOT_CMD} bash -c "echo '%aur_builder ALL=(ALL) NOPASSWD: /usr/bin/pacman' > /etc/sudoers.d/aur_builder"
|
||||
${ROOT_CMD} chmod 0440 /etc/sudoers.d/aur_builder
|
||||
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
RUN_AS_AUR=(sudo -u aur_builder bash -lc)
|
||||
else
|
||||
RUN_AS_AUR=(su - aur_builder -c)
|
||||
fi
|
||||
|
||||
echo "[aur-builder-setup] Ensuring yay is installed for aur_builder..."
|
||||
if ! "${RUN_AS_AUR[@]}" 'command -v yay >/dev/null 2>&1'; then
|
||||
"${RUN_AS_AUR[@]}" 'cd ~ && rm -rf yay && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si --noconfirm'
|
||||
else
|
||||
echo "[aur-builder-setup] yay already installed."
|
||||
fi
|
||||
|
||||
echo "[aur-builder-setup] Done."
|
||||
30
scripts/installation/arch/dependencies.sh
Executable file
30
scripts/installation/arch/dependencies.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
echo "[arch/dependencies] Installing Arch build dependencies..."
|
||||
|
||||
pacman -Syu --noconfirm
|
||||
pacman -S --noconfirm --needed \
|
||||
base-devel \
|
||||
git \
|
||||
rsync \
|
||||
curl \
|
||||
ca-certificates \
|
||||
xz
|
||||
|
||||
pacman -Scc --noconfirm
|
||||
|
||||
# Always run AUR builder setup for Arch
|
||||
AUR_SETUP="${SCRIPT_DIR}/aur-builder-setup.sh"
|
||||
|
||||
if [[ ! -x "${AUR_SETUP}" ]]; then
|
||||
echo "[arch/dependencies] ERROR: AUR builder setup script not found or not executable: ${AUR_SETUP}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[arch/dependencies] Running AUR builder setup..."
|
||||
bash "${AUR_SETUP}"
|
||||
|
||||
echo "[arch/dependencies] Done."
|
||||
19
scripts/installation/arch/package.sh
Executable file
19
scripts/installation/arch/package.sh
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[arch/package] Building Arch package (makepkg --nodeps)..."
|
||||
|
||||
if id aur_builder >/dev/null 2>&1; then
|
||||
echo "[arch/package] Using 'aur_builder' user for makepkg..."
|
||||
chown -R aur_builder:aur_builder "$(pwd)"
|
||||
su aur_builder -c "cd '$(pwd)' && rm -f package-manager-*.pkg.tar.* && makepkg --noconfirm --clean --nodeps"
|
||||
else
|
||||
echo "[arch/package] WARNING: user 'aur_builder' not found, running makepkg as current user..."
|
||||
rm -f package-manager-*.pkg.tar.*
|
||||
makepkg --noconfirm --clean --nodeps
|
||||
fi
|
||||
|
||||
echo "[arch/package] Installing generated Arch package..."
|
||||
pacman -U --noconfirm package-manager-*.pkg.tar.*
|
||||
|
||||
echo "[arch/package] Done."
|
||||
20
scripts/installation/centos/dependencies.sh
Executable file
20
scripts/installation/centos/dependencies.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[centos/dependencies] Installing CentOS build dependencies..."
|
||||
|
||||
dnf -y update
|
||||
dnf -y install \
|
||||
git \
|
||||
rsync \
|
||||
rpm-build \
|
||||
make \
|
||||
gcc \
|
||||
bash \
|
||||
curl-minimal \
|
||||
ca-certificates \
|
||||
xz
|
||||
|
||||
dnf clean all
|
||||
|
||||
echo "[centos/dependencies] Done."
|
||||
46
scripts/installation/centos/package.sh
Executable file
46
scripts/installation/centos/package.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[centos/package] Setting up rpmbuild directories..."
|
||||
mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
|
||||
|
||||
echo "[centos/package] Extracting version from package-manager.spec..."
|
||||
version="$(grep -E '^Version:' package-manager.spec | awk '{print $2}')"
|
||||
if [[ -z "${version}" ]]; then
|
||||
echo "ERROR: Version missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
srcdir="package-manager-${version}"
|
||||
echo "[centos/package] Preparing source tree: ${srcdir}"
|
||||
rm -rf "/tmp/${srcdir}"
|
||||
mkdir -p "/tmp/${srcdir}"
|
||||
cp -a . "/tmp/${srcdir}/"
|
||||
|
||||
echo "[centos/package] Creating source tarball..."
|
||||
tar czf "/root/rpmbuild/SOURCES/${srcdir}.tar.gz" -C /tmp "${srcdir}"
|
||||
|
||||
echo "[centos/package] Copying SPEC..."
|
||||
cp package-manager.spec /root/rpmbuild/SPECS/
|
||||
|
||||
echo "[centos/package] Running rpmbuild..."
|
||||
cd /root/rpmbuild/SPECS
|
||||
rpmbuild -bb package-manager.spec
|
||||
|
||||
echo "[centos/package] Installing generated RPM (local, offline, forced reinstall)..."
|
||||
rpm_path="$(find /root/rpmbuild/RPMS -name 'package-manager-*.rpm' | head -n1)"
|
||||
if [[ -z "${rpm_path}" ]]; then
|
||||
echo "ERROR: RPM not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Forced reinstall, always overwrite old version
|
||||
# ------------------------------------------------------------
|
||||
echo "[centos/package] Forcing reinstall via rpm -Uvh --replacepkgs --force"
|
||||
rpm -Uvh --replacepkgs --force "${rpm_path}"
|
||||
|
||||
# Keep structure: remove temp directory afterwards
|
||||
rm -rf "/tmp/${srcdir}"
|
||||
|
||||
echo "[centos/package] Done."
|
||||
20
scripts/installation/debian/dependencies.sh
Executable file
20
scripts/installation/debian/dependencies.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[debian/dependencies] Installing Debian build dependencies..."
|
||||
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
debhelper \
|
||||
dpkg-dev \
|
||||
git \
|
||||
rsync \
|
||||
bash \
|
||||
curl \
|
||||
ca-certificates \
|
||||
xz-utils
|
||||
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
echo "[debian/dependencies] Done."
|
||||
13
scripts/installation/debian/package.sh
Executable file
13
scripts/installation/debian/package.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[debian/package] Building Debian package..."
|
||||
|
||||
dpkg-buildpackage -us -uc -b
|
||||
|
||||
echo "[debian/package] Installing generated DEB package..."
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y ./../package-manager_*.deb
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
echo "[debian/package] Done."
|
||||
21
scripts/installation/fedora/dependencies.sh
Executable file
21
scripts/installation/fedora/dependencies.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[fedora/dependencies] Installing Fedora build dependencies..."
|
||||
|
||||
dnf -y update
|
||||
dnf -y install \
|
||||
git \
|
||||
rsync \
|
||||
rpm-build \
|
||||
make \
|
||||
gcc \
|
||||
bash \
|
||||
curl \
|
||||
ca-certificates \
|
||||
python3 \
|
||||
xz
|
||||
|
||||
dnf clean all
|
||||
|
||||
echo "[fedora/dependencies] Done."
|
||||
43
scripts/installation/fedora/package.sh
Executable file
43
scripts/installation/fedora/package.sh
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[fedora/package] Setting up rpmbuild directories..."
|
||||
mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
|
||||
|
||||
echo "[fedora/package] Extracting version from package-manager.spec..."
|
||||
version="$(grep -E '^Version:' package-manager.spec | awk '{print $2}')"
|
||||
if [[ -z "${version}" ]]; then
|
||||
echo "ERROR: Version missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
srcdir="package-manager-${version}"
|
||||
echo "[fedora/package] Preparing source tree: ${srcdir}"
|
||||
rm -rf "/tmp/${srcdir}"
|
||||
mkdir -p "/tmp/${srcdir}"
|
||||
cp -a . "/tmp/${srcdir}/"
|
||||
|
||||
echo "[fedora/package] Creating source tarball..."
|
||||
tar czf "/root/rpmbuild/SOURCES/${srcdir}.tar.gz" -C /tmp "${srcdir}"
|
||||
|
||||
echo "[fedora/package] Copying SPEC..."
|
||||
cp package-manager.spec /root/rpmbuild/SPECS/
|
||||
|
||||
echo "[fedora/package] Running rpmbuild..."
|
||||
cd /root/rpmbuild/SPECS
|
||||
rpmbuild -bb package-manager.spec
|
||||
|
||||
echo "[fedora/package] Installing generated RPM (local, offline, forced reinstall)..."
|
||||
rpm_path="$(find /root/rpmbuild/RPMS -name 'package-manager-*.rpm' | head -n1)"
|
||||
if [[ -z "${rpm_path}" ]]; then
|
||||
echo "ERROR: RPM not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Always force (re)install the freshly built RPM, even if the same
|
||||
# version is already installed. This is what we want in dev/test containers.
|
||||
rpm -Uvh --replacepkgs --force "${rpm_path}"
|
||||
|
||||
rm -rf "/tmp/${srcdir}"
|
||||
|
||||
echo "[fedora/package] Done."
|
||||
12
scripts/installation/lib.sh
Executable file
12
scripts/installation/lib.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/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
|
||||
}
|
||||
89
scripts/installation/main.sh
Executable file
89
scripts/installation/main.sh
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# main.sh
|
||||
#
|
||||
# Developer setup entrypoint.
|
||||
#
|
||||
# Responsibilities:
|
||||
# - If inside a Nix shell (IN_NIX_SHELL=1):
|
||||
# * Skip venv creation and dependency installation
|
||||
# * Run `python3 main.py install`
|
||||
# - Otherwise:
|
||||
# * Create ~/.venvs/pkgmgr virtual environment if missing
|
||||
# * Install Python dependencies into that venv
|
||||
# * Append auto-activation to ~/.bashrc and ~/.zshrc
|
||||
# * Run `main.py install` using the venv Python
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo "[installation/main] Starting developer setup..."
|
||||
|
||||
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
cd "${PROJECT_ROOT}"
|
||||
|
||||
VENV_DIR="${HOME}/.venvs/pkgmgr"
|
||||
RC_LINE='if [ -d "${HOME}/.venvs/pkgmgr" ]; then . "${HOME}/.venvs/pkgmgr/bin/activate"; if [ -n "${PS1:-}" ]; then echo "Global Python virtual environment '\''~/.venvs/pkgmgr'\'' activated."; fi; fi'
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Nix shell mode: do not touch venv, only run main.py install
|
||||
# ------------------------------------------------------------
|
||||
if [[ -n "${IN_NIX_SHELL:-}" ]]; then
|
||||
echo "[installation/main] Nix shell detected (IN_NIX_SHELL=1)."
|
||||
echo "[installation/main] Skipping virtualenv creation and dependency installation."
|
||||
echo "[installation/main] Running main.py install via system python3..."
|
||||
python3 main.py install
|
||||
echo "[installation/main] Developer setup finished (Nix mode)."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Normal host mode: create/update venv and run main.py install
|
||||
# ------------------------------------------------------------
|
||||
|
||||
echo "[installation/main] Ensuring main.py is executable..."
|
||||
chmod +x main.py || true
|
||||
|
||||
echo "[installation/main] Ensuring global virtualenv root: ${HOME}/.venvs"
|
||||
mkdir -p "${HOME}/.venvs"
|
||||
|
||||
if [[ ! -d "${VENV_DIR}" ]]; then
|
||||
echo "[installation/main] Creating virtual environment at: ${VENV_DIR}"
|
||||
python3 -m venv "${VENV_DIR}"
|
||||
else
|
||||
echo "[installation/main] Virtual environment already exists at: ${VENV_DIR}"
|
||||
fi
|
||||
|
||||
echo "[installation/main] Installing Python tooling into venv..."
|
||||
"${VENV_DIR}/bin/python" -m ensurepip --upgrade
|
||||
"${VENV_DIR}/bin/pip" install --upgrade pip setuptools wheel
|
||||
|
||||
if [[ -f "requirements.txt" ]]; then
|
||||
echo "[installation/main] Installing dependencies from requirements.txt..."
|
||||
"${VENV_DIR}/bin/pip" install -r requirements.txt
|
||||
elif [[ -f "_requirements.txt" ]]; then
|
||||
echo "[installation/main] Installing dependencies from _requirements.txt..."
|
||||
"${VENV_DIR}/bin/pip" install -r _requirements.txt
|
||||
else
|
||||
echo "[installation/main] No requirements.txt or _requirements.txt found. Skipping dependency installation."
|
||||
fi
|
||||
|
||||
echo "[installation/main] Ensuring ~/.bashrc and ~/.zshrc exist..."
|
||||
touch "${HOME}/.bashrc" "${HOME}/.zshrc"
|
||||
|
||||
echo "[installation/main] Ensuring venv auto-activation is present in shell rc files..."
|
||||
for rc in "${HOME}/.bashrc" "${HOME}/.zshrc"; do
|
||||
if ! grep -qxF "${RC_LINE}" "$rc"; then
|
||||
echo "${RC_LINE}" >> "$rc"
|
||||
echo "[installation/main] Appended auto-activation to $rc"
|
||||
else
|
||||
echo "[installation/main] Auto-activation already present in $rc"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "[installation/main] Running main.py install via venv Python..."
|
||||
"${VENV_DIR}/bin/python" main.py install
|
||||
|
||||
echo
|
||||
echo "[installation/main] Developer setup complete."
|
||||
echo "Restart your shell (or run 'exec bash' or 'exec zsh') to activate the environment."
|
||||
29
scripts/installation/run-dependencies.sh
Executable file
29
scripts/installation/run-dependencies.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
OS_ID="$(detect_os_id)"
|
||||
|
||||
echo "[run-dependencies] Detected OS: ${OS_ID}"
|
||||
|
||||
case "${OS_ID}" in
|
||||
arch|debian|ubuntu|fedora|centos)
|
||||
DEP_SCRIPT="${SCRIPT_DIR}/${OS_ID}/dependencies.sh"
|
||||
;;
|
||||
*)
|
||||
echo "[run-dependencies] Unsupported OS: ${OS_ID}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ! -f "${DEP_SCRIPT}" ]]; then
|
||||
echo "[run-dependencies] Dependency script not found: ${DEP_SCRIPT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[run-dependencies] Executing: ${DEP_SCRIPT}"
|
||||
exec bash "${DEP_SCRIPT}"
|
||||
29
scripts/installation/run-package.sh
Executable file
29
scripts/installation/run-package.sh
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
OS_ID="$(detect_os_id)"
|
||||
|
||||
echo "[run-package] Detected OS: ${OS_ID}"
|
||||
|
||||
case "${OS_ID}" in
|
||||
arch|debian|ubuntu|fedora|centos)
|
||||
PKG_SCRIPT="${SCRIPT_DIR}/${OS_ID}/package.sh"
|
||||
;;
|
||||
*)
|
||||
echo "[run-package] Unsupported OS: ${OS_ID}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ! -f "${PKG_SCRIPT}" ]]; then
|
||||
echo "[run-package] Package script not found: ${PKG_SCRIPT}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[run-package] Executing: ${PKG_SCRIPT}"
|
||||
exec bash "${PKG_SCRIPT}"
|
||||
22
scripts/installation/ubuntu/dependencies.sh
Executable file
22
scripts/installation/ubuntu/dependencies.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[ubuntu/dependencies] Installing Ubuntu build dependencies..."
|
||||
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
debhelper \
|
||||
dpkg-dev \
|
||||
git \
|
||||
tzdata \
|
||||
lsb-release \
|
||||
rsync \
|
||||
bash \
|
||||
curl \
|
||||
ca-certificates \
|
||||
xz-utils
|
||||
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
echo "[ubuntu/dependencies] Done."
|
||||
13
scripts/installation/ubuntu/package.sh
Executable file
13
scripts/installation/ubuntu/package.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "[ubuntu/package] Building Ubuntu (Debian-style) package..."
|
||||
|
||||
dpkg-buildpackage -us -uc -b
|
||||
|
||||
echo "[ubuntu/package] Installing generated DEB package..."
|
||||
apt-get update
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y ./../package-manager_*.deb
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
echo "[ubuntu/package] Done."
|
||||
Reference in New Issue
Block a user