Browse Source

Allow command strings to be passed to container

bryan 3 days ago
parent
commit
007b8c4304
1 changed files with 10 additions and 6 deletions
  1. 10 6
      installJRMC

+ 10 - 6
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