#!/usr/bin/env bash
# =============================================================================
#  download-rpms.sh - OPTIONAL helper, run on a machine WITH internet access
# =============================================================================
#
#  Only needed when the offline RHEL 9.6 host has no local RHEL repository
#  (for example no mounted RHEL 9.6 DVD / ISO).
#
#  Run this on an online RHEL 9.6 x86_64 machine that has the same packages
#  installed as the offline host (ideally a copy of it). It downloads
#  samba, samba-client, cifs-utils, python3-samba, fio, nftables and
#  policycoreutils-python-utils (semanage, for SELinux), and every
#  dependency that machine is missing, into ./rpms/. Copy the whole kit
#  folder, including rpms/, to the offline host; start-samba.sh then
#  installs from rpms/ without any network access.
#
#  USAGE:   sudo ./download-rpms.sh
# =============================================================================

set -euo pipefail

KIT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
RPM_DIR="$KIT_DIR/rpms"
PACKAGES=(samba samba-client cifs-utils python3-samba fio nftables policycoreutils-python-utils)

source /etc/os-release
if [[ $ID != rhel || $VERSION_ID != 9.6 ]]; then
    echo "[ WARN ] This machine is '$PRETTY_NAME'. For the best match use RHEL 9.6." >&2
fi

mkdir -p "$RPM_DIR"

# --resolve downloads the dependencies that are not installed on this machine.
dnf download --resolve --arch x86_64 --arch noarch --destdir "$RPM_DIR" "${PACKAGES[@]}"

echo
echo "[  OK  ] Downloaded into $RPM_DIR:"
ls -1 "$RPM_DIR"
echo
echo "Next: copy the whole folder '$KIT_DIR' to the offline host and run ./start-samba.sh"
