diff --git a/Containerfile b/Containerfile index f550b96b..e4aab642 100644 --- a/Containerfile +++ b/Containerfile @@ -538,6 +538,20 @@ RUN rpm-ostree install \ sed -i~ -E 's/=.\$\(command -v (nft|ip6?tables-legacy).*/=/g' /usr/lib/waydroid/data/scripts/waydroid-net.sh && \ ostree container commit +# Install Homebrew on Image +RUN touch /.dockerenv && \ + mkdir -p /var/home && \ + mkdir -p /var/roothome && \ + curl -Lo /tmp/brew-install https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh && \ + chmod +x /tmp/brew-install && \ + /tmp/brew-install && \ + /home/linuxbrew/.linuxbrew/bin/brew update && \ + cp -R /home/linuxbrew /usr/share/homebrew && \ + chown -R 1000:1000 /usr/share/homebrew && \ + rm -f /usr/share/homebrew/.linuxbrew/Homebrew/Library/Homebrew/cmd/update.sh && \ + rm -f /usr/share/homebrew/.linuxbrew/Homebrew/Library/Homebrew/cmd/update-reset.sh && \ + ostree container commit + # Cleanup & Finalize COPY system_files/overrides / RUN /usr/libexec/containerbuild/build-initramfs && \ @@ -599,6 +613,9 @@ RUN /usr/libexec/containerbuild/build-initramfs && \ sed -i 's/#DefaultTimeoutStopSec.*/DefaultTimeoutStopSec=15s/' /usr/lib/systemd/system.conf && \ mkdir -p /usr/etc/flatpak/remotes.d && \ curl -Lo /usr/etc/flatpak/remotes.d/flathub.flatpakrepo https://dl.flathub.org/repo/flathub.flatpakrepo && \ + systemctl enable var-home-linuxbrew.mount && \ + systemctl enable brew-upgrade.timer && \ + systemctl enable brew-update.timer && \ systemctl enable com.system76.Scheduler.service && \ systemctl enable btrfs-dedup@var-home.timer && \ systemctl enable displaylink.service && \ diff --git a/system_files/desktop/shared/usr/etc/profile.d/brew-bash-completion.sh b/system_files/desktop/shared/usr/etc/profile.d/brew-bash-completion.sh new file mode 100644 index 00000000..424ac4ad --- /dev/null +++ b/system_files/desktop/shared/usr/etc/profile.d/brew-bash-completion.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# shellcheck shell=sh disable=SC1091,SC2039,SC2166 +# Check for interactive bash and that we haven't already been sourced. +if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${BREW_BASH_COMPLETION-}" = x ]; then + + # Check for recent enough version of bash. + if [ "${BASH_VERSINFO[0]}" -gt 4 ] || + [ "${BASH_VERSINFO[0]}" -eq 4 -a "${BASH_VERSINFO[1]}" -ge 2 ]; then + if [ -w /home/linuxbrew/.linuxbrew ]; then + if ! test -L /home/linuxbrew/.linuxbrew/etc/bash_completion.d/brew; then + /home/linuxbrew/.linuxbrew/bin/brew completions link > /dev/null + fi + fi + if test -d /home/linuxbrew/.linuxbrew/etc/bash_completion.d; then + for rc in /home/linuxbrew/.linuxbrew/etc/bash_completion.d/*; do + if test -r "$rc"; then + . "$rc" + fi + done + unset rc + fi + fi + BREW_BASH_COMPLETION=1 + export BREW_BASH_COMPLETION +fi diff --git a/system_files/desktop/shared/usr/etc/profile.d/brew-on-image.sh b/system_files/desktop/shared/usr/etc/profile.d/brew-on-image.sh new file mode 100644 index 00000000..52baa0eb --- /dev/null +++ b/system_files/desktop/shared/usr/etc/profile.d/brew-on-image.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +if systemctl --quiet is-active var-home-linuxbrew.mount; then + HOMEBREW_NO_AUTO_UPDATE=1 + export HOMEBREW_NO_AUTO_UPDATE +fi diff --git a/system_files/desktop/shared/usr/lib/systemd/system/brew-update.service b/system_files/desktop/shared/usr/lib/systemd/system/brew-update.service new file mode 100644 index 00000000..e28dc7b2 --- /dev/null +++ b/system_files/desktop/shared/usr/lib/systemd/system/brew-update.service @@ -0,0 +1,13 @@ +[Unit] +Description=Auto update brew for mutable brew installs +After=local-fs.target +After=network-online.target +ConditionPathIsMountPoint=!/var/home/linuxbrew +ConditionPathExists=/home/linuxbrew/.linuxbrew/bin/brew + +[Service] +# Override the user if different UID/User +User=1000 +Type=oneshot +ExecStart=/home/linuxbrew/.linuxbrew/bin/brew update +StandardOutput=journal diff --git a/system_files/desktop/shared/usr/lib/systemd/system/brew-update.timer b/system_files/desktop/shared/usr/lib/systemd/system/brew-update.timer new file mode 100644 index 00000000..d0226f33 --- /dev/null +++ b/system_files/desktop/shared/usr/lib/systemd/system/brew-update.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Timer for brew update for mutable brew +Wants=network-online.target + +[Timer] +OnBootSec=20min +OnUnitInactiveSec=6h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/system_files/desktop/shared/usr/lib/systemd/system/brew-upgrade.service b/system_files/desktop/shared/usr/lib/systemd/system/brew-upgrade.service new file mode 100644 index 00000000..1d8b283d --- /dev/null +++ b/system_files/desktop/shared/usr/lib/systemd/system/brew-upgrade.service @@ -0,0 +1,13 @@ +[Unit] +Description=Upgrade Brew packages +After=local-fs.target +After=network-online.target +ConditionPathExists=/home/linuxbrew/.linuxbrew/bin/brew + +[Service] +# Override the user if different UID/User +User=1000 +Type=oneshot +Environment=HOMEBREW_NO_AUTO_UPDATE=1 +ExecStart=/home/linuxbrew/.linuxbrew/bin/brew upgrade +StandardOutput=journal diff --git a/system_files/desktop/shared/usr/lib/systemd/system/brew-upgrade.timer b/system_files/desktop/shared/usr/lib/systemd/system/brew-upgrade.timer new file mode 100644 index 00000000..20f7cacd --- /dev/null +++ b/system_files/desktop/shared/usr/lib/systemd/system/brew-upgrade.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Timer for brew upgrade for on image brew +Wants=network-online.target + +[Timer] +OnBootSec=20min +OnUnitInactiveSec=6h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/system_files/desktop/shared/usr/lib/systemd/system/cleanup-homebrew.service b/system_files/desktop/shared/usr/lib/systemd/system/cleanup-homebrew.service new file mode 100644 index 00000000..006f4021 --- /dev/null +++ b/system_files/desktop/shared/usr/lib/systemd/system/cleanup-homebrew.service @@ -0,0 +1,16 @@ +[Unit] +Description=Cleanup Homebrew workdir +After=var.mount +Before=var-home-linuxbrew.mount +ConditionPathIsDirectory=%C/homebrew + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=-/usr/bin/rm -rf %C/homebrew/.* +ExecStart=-/usr/bin/rm -rf %C/homebrew/* +ExecStop=-/usr/bin/rm -rf %C/homebrew/.* +ExecStop=-/usr/bin/rm -rf %C/homebrew/* + +[Install] +WantedBy=default.target multi-user.target diff --git a/system_files/desktop/shared/usr/lib/systemd/system/var-home-linuxbrew.mount b/system_files/desktop/shared/usr/lib/systemd/system/var-home-linuxbrew.mount new file mode 100644 index 00000000..bd10ff01 --- /dev/null +++ b/system_files/desktop/shared/usr/lib/systemd/system/var-home-linuxbrew.mount @@ -0,0 +1,17 @@ +[Unit] +Description=Homebrew overlay mount +Wants=cleanup-homebrew.service +After=cleanup-homebrew.service +After=var-mount.mount +ConditionPathIsDirectory=%S/homebrew +ConditionPathIsDirectory=%C/homebrew +ConditionPathExists=!/var/home/linuxbrew/.linuxbrew + +[Mount] +Type=overlay +What=overlay +Options=lowerdir=/usr/share/homebrew,upperdir=%S/homebrew,workdir=%C/homebrew +Where=/var/home/linuxbrew + +[Install] +WantedBy=local-fs.target diff --git a/system_files/desktop/shared/usr/lib/tmpfiles.d/homebrew.conf b/system_files/desktop/shared/usr/lib/tmpfiles.d/homebrew.conf new file mode 100644 index 00000000..92cd2fd8 --- /dev/null +++ b/system_files/desktop/shared/usr/lib/tmpfiles.d/homebrew.conf @@ -0,0 +1,3 @@ +d /var/lib/homebrew 0755 1000 1000 - - +d /var/cache/homebrew 0755 1000 1000 - - +d /var/home/linuxbrew 0755 1000 1000 - - diff --git a/system_files/overrides/usr/share/fish/vendor_conf.d/brew.fish b/system_files/overrides/usr/share/fish/vendor_conf.d/brew.fish new file mode 100644 index 00000000..86f7bc11 --- /dev/null +++ b/system_files/overrides/usr/share/fish/vendor_conf.d/brew.fish @@ -0,0 +1,21 @@ +#!/usr/bin/fish +#shellcheck disable=all +if status --is-interactive + if [ -d /home/linuxbrew/.linuxbrew ] + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + if [ -w /home/linuxbrew/.linuxbrew ] + if [ ! -L (brew --prefix)/share/fish/vendor_completions.d/brew] + brew completions link > /dev/null + end + end + if test -d (brew --prefix)/share/fish/completions + set -p fish_complete_path (brew --prefix)/share/fish/completions + end + if test -d (brew --prefix)/share/fish/vendor_completions.d + set -p fish_complete_path (brew --prefix)/share/fish/vendor_completions.d + end + end + if systemctl --quiet is-active var-home-linuxbrew.mount + set -gx HOMEBREW_NO_AUTO_UPDATE 1 + end +end