From 784bc48ce9993745a1d3b83f1436f3e874ca55e8 Mon Sep 17 00:00:00 2001 From: m2Giles <69128853+m2Giles@users.noreply.github.com> Date: Thu, 4 Jan 2024 13:33:20 -0500 Subject: [PATCH] feat(bluefin-cli): Persist State of Cellar Persist the state of Homebrew's Cellar for #768 If the Cellar does not exist. It will be created in the User's home directory. It is then volume mounted into the container making it accessible on any distrobox enter for the container. This also uses the brew_pkgs as a brewfile and brew_script to install/reinstall packages. The brew_script will first try to relink everything in the Cellar. However, just because an item is relink, doesn't mean it will be able to run necessitating a reinstall. Fortunately, any specified reinstalls seem to be quick. --- just/custom.just | 18 ++++++++++++------ toolboxes/Containerfile.bluefin-cli | 6 +++++- toolboxes/brew_script.bluefin-cli | 19 +++++++++++++++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/just/custom.just b/just/custom.just index dab9f3136eb..683e9d26472 100644 --- a/just/custom.just +++ b/just/custom.just @@ -25,14 +25,20 @@ aqua: [private] bluefin-cli: - #!/usr/bin/env bash - if [ ! -f "${HOME}/.brew_pkgs" ]; then - echo dysk > "${HOME}/.brew_pkgs" - fi; - distrobox-create --nvidia --image ghcr.io/ublue-os/bluefin-cli:latest -n bluefin -Y -a "--env BREW_PKGS=.brew_pkgs" - echo "Entering bluefin-cli" + #!/usr/bin/env bash + if [ ! -f "${HOME}/.brew_pkgs" ]; then + echo dysk > "${HOME}/.brew_pkgs" + fi; + if [ ! -d "${HOME}/.homebrew/Cellar" ]; then + mkdir -p "${HOME}/.homebrew/Cellar" + fi; + distrobox-create --nvidia --image localhost/bluefin-cli:latest -n bluefin -Y -a "--env BREW_PKGS=.brew_pkgs" --volume "${HOME}/.homebrew/Cellar":/home/linuxbrew/.linuxbrew/Cellar + echo "Setting up bluefin-cli" + distrobox enter bluefin -- brew_script + echo "Entering bluefin-cli" distrobox enter bluefin + # Enable Cockpit for web-based system management | https://cockpit-project.org/ cockpit: echo 'Enabling Cockpit' diff --git a/toolboxes/Containerfile.bluefin-cli b/toolboxes/Containerfile.bluefin-cli index 438f8d288d4..502047c2b02 100644 --- a/toolboxes/Containerfile.bluefin-cli +++ b/toolboxes/Containerfile.bluefin-cli @@ -7,6 +7,10 @@ LABEL com.github.containers.toolbox="true" \ COPY ./toolboxes/packages.bluefin-cli /toolbox-packages +# Install brew_script +COPY ./toolboxes/brew_script.bluefin-cli /tmp/brew_script +RUN install -Dm755 /tmp/brew_script /usr/bin/brew_script + # Update image RUN apk update && \ apk upgrade @@ -36,7 +40,7 @@ COPY ./toolboxes/files.bluefin-cli/etc/sudoers /etc/sudoers COPY ./toolboxes/files.bluefin-cli/etc/pam.d /etc/pam.d # Have Linuxbrew owned by UID = 1000 -RUN chown -R 1000 /home/linuxbrew/.linuxbrew /home/linuxbrew/.linuxbrew/bin +RUN chown -R 1000 /home/linuxbrew # Change root shell to BASH diff --git a/toolboxes/brew_script.bluefin-cli b/toolboxes/brew_script.bluefin-cli index ede4ecc32e4..c838547d439 100644 --- a/toolboxes/brew_script.bluefin-cli +++ b/toolboxes/brew_script.bluefin-cli @@ -1,8 +1,23 @@ #!/usr/bin/env bash if [ ! -f /home/linuxbrew/.firstrun ] && [ -n "${BREW_PKGS}" ]; then touch /home/linuxbrew/.firstrun + # `brew update-reset` is currently needed # because somekind of issue with brew - brew update-reset - xargs brew install < "${HOME}"/"${BREW_PKGS}" + # /home/linuxbrew/.linuxbrew/bin/brew update-reset + + # Package Install/Reinstall/Relink + if [ -n "$(ls -A /home/linuxbrew/.linuxbrew/Cellar)" ]; then + echo "Relinking packages. You may still need to reinstall binaries to run them" + /home/linuxbrew/.linuxbrew/bin/brew list -1 | while read line + do + /home/linuxbrew/.linuxbrew/bin/brew unlink $line + /home/linuxbrew/.linuxbrew/bin/brew link $line + done + echo "Reinstalling Packages from brewfile ${HOME}/${BREW_PKGS}" + xargs /home/linuxbrew/.linuxbrew/bin/brew reinstall < "${HOME}"/"${BREW_PKGS}" + else + echo "Installing Packages from brewfile ${HOME}/${BREW_PKGS}" + xargs /home/linuxbrew/.linuxbrew/bin/brew install < "${HOME}"/"${BREW_PKGS}" + fi fi