diff --git a/modules/brew/README.md b/modules/brew/README.md index 22bfd91..5a03f78 100644 --- a/modules/brew/README.md +++ b/modules/brew/README.md @@ -7,6 +7,7 @@ The brew module installs [Homebrew / Linuxbrew](https://brew.sh/) on your system - Sets up systemd services to automatically update Brew to the latest version. - Sets up systemd services to automatically upgrade Brew packages. - Sets up bash and fish completions for Brew. +- Installs specific Brew packages if specified in the `install` configuration. ## How it works @@ -50,6 +51,7 @@ The brew module installs [Homebrew / Linuxbrew](https://brew.sh/) on your system **Rest of the setup:** - `brew-update` runs at the specified time to update Brew to the latest version - `brew-upgrade` runs at the specified time to upgrade Brew packages +- `brew-packages-setup` installs the specified packages if listed in the `install` configuration ## Development Setting `DEBUG=true` inside `brew.sh` will enable additional output for debugging purposes during development. diff --git a/modules/brew/brew.sh b/modules/brew/brew.sh index 4f98a77..2aded96 100644 --- a/modules/brew/brew.sh +++ b/modules/brew/brew.sh @@ -79,6 +79,11 @@ if [[ -z "${BREW_ANALYTICS}" || "${BREW_ANALYTICS}" == "null" ]]; then BREW_ANALYTICS=true fi +INSTALL_PACKAGES=$(echo "${1}" | yq -I=0 ".install[]") +if [[ -z "${INSTALL_PACKAGES}" || "${INSTALL_PACKAGES}" == "null" ]]; then + INSTALL_PACKAGES=() +fi + # Create necessary directories mkdir -p /var/home mkdir -p /var/roothome @@ -277,4 +282,64 @@ if [[ "${BREW_ANALYTICS}" == false ]]; then fi fi +# Create directory for brew configuration +mkdir -p /usr/share/bluebuild/brew + +# Create repo-info.yml file with install packages if specified +if [[ -n "${INSTALL_PACKAGES}" ]]; then + echo "install:" > /usr/share/bluebuild/brew/repo-info.yml + echo "${INSTALL_PACKAGES}" | sed 's/^/ - /' >> /usr/share/bluebuild/brew/repo-info.yml + echo "The following Brew packages will be installed when the system is live:" + echo "${INSTALL_PACKAGES}" | sed 's/^/ - /' + + # Write brew-packages-setup script + cat > /usr/bin/brew-packages-setup < /dev/null; then + brew install "\$package" + else + echo "Package \$package is already installed." + fi + done +else + echo "No Brew packages specified for installation." +fi +EOF + + chmod +x /usr/bin/brew-packages-setup + + # Write brew-packages-setup service + cat > /usr/lib/systemd/system/brew-packages-setup.service <; +}