From 007b8c4304f666b605599ebda83b49cf1aec268f Mon Sep 17 00:00:00 2001 From: bryan Date: Thu, 24 Apr 2025 13:45:59 -0400 Subject: [PATCH] Allow command strings to be passed to container --- installJRMC | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/installJRMC b/installJRMC index c049a5f..d2a51f0 100755 --- a/installJRMC +++ b/installJRMC @@ -420,7 +420,7 @@ get_latest_mc_version() { local mc_version_source # Containerized package manager - if apt_mc_container && + if create_mc_apt_container && MC_VERSION=$(sudo buildah run "$CNT" -- apt-cache policy "mediacenter${USER_MC_MVERSION:-${MC_VERSION%%.*}}" | grep Candidate | awk '{print $2}' | sort -V | tail -n1) && execute sudo buildah rm "$CNT" && [[ $MC_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then @@ -772,14 +772,12 @@ acquire_deb_new() { fi # Define the repositories to search - if ! (apt_mc_container && - sudo buildah run "$CNT" -- sh -c " - apt-get download --allow-unauthenticated mediacenter$MC_MVERSION" && + if ! (create_mc_apt_container "apt-get download --allow-unauthenticated mediacenter$MC_MVERSION" && mnt="$(sudo buildah mount "$CNT")" && execute sudo find "$mnt" -maxdepth 1 -type f -name "*.deb" -exec cp {} "$MC_DEB" \; && + execute sudo chown "$USER:$USER" "$MC_DEB" && execute sudo buildah umount "$CNT" && execute sudo buildah rm "$CNT" && - execute sudo chown "$USER:$USER" "$MC_DEB" && [[ -f $MC_DEB ]]); then err "Failed to download DEB from containerized package manager" echo "Using legacy download method" @@ -1864,8 +1862,9 @@ download() { debug "${cmd[@]}" "$url" "${cmd[@]}" "$url" } -apt_mc_container() { +create_mc_apt_container() { declare -g CNT + local -a cmds=("$@") install_package --silent buildah &>/dev/null && CNT=$(sudo buildah from --quiet alpine:edge 2>/dev/null) && sudo buildah run "$CNT" -- sh -c ' @@ -1880,6 +1879,11 @@ apt_mc_container() { Architectures: '"$MC_ARCH"' EOF apt-get update --allow-insecure-repositories &>/dev/null' + + # If user passes command strings run them in the container + for cmd in "${cmds[@]}"; do + sudo buildah run "$CNT" -- sh -c "$cmd" + done } # Roughly turn debugging on for pre-init