Skip to content

About

Daily Homebrew auto-update via launchd — reliable on sleep/shutdown, fault-tolerant, no passwordless sudo

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

brew-daily-autoupdate

A small, dependency-free launchd agent that keeps Homebrew updated once a day on macOS — reliably, even on a laptop that sleeps or shuts down, and without ever granting passwordless sudo.

It runs brew update, brew upgrade (formulae + safe casks) and brew cleanup on a daily schedule, then shows a desktop notification.


Why this exists

The popular DomT4/homebrew-autoupdate tap is great, but its launchd agent uses StartInterval (a relative timer). On a laptop that is asleep or powered off when the timer would fire, runs get silently skipped and the relative timer resets on every reboot — so days can pass with no update.

This project fixes that and adds a few practical safeguards:

Concern StartInterval (typical setup) brew-daily-autoupdate
Missed runs while asleep / off Skipped, timer resets on reboot StartCalendarInterval at 3 times/day; macOS catches up on next wake/boot
One cask failing aborts everything && chain stops; cleanup never runs Every step is fault-tolerant; cleanup + notification always run
GUI apps that update themselves May be force-upgraded with --greedy No --greedy → self-updating casks are skipped
Casks that need sudo Often fail headless, or require passwordless sudo Excluded by name — never edits /etc/sudoers
Running 3 times/day Would upgrade repeatedly Once-per-day stamp → real work runs once per calendar day

Design

The wrapper (brew_autoupdate) does, in order:

  1. Once-per-day guard — a stamp file (last_run_date) ensures the heavy upgrade runs only once per calendar day, even though launchd triggers it at 09:00, 14:00 and 21:00. The extra slots exist purely so a machine that was asleep/off at 09:00 still gets caught later.
  2. brew update then brew upgrade --formula.
  3. brew upgrade --cask without --greedy (so GUI self-updating apps are left alone), minus any cask matching EXCLUDE_CASKS.
  4. brew cleanup.
  5. A desktop notification via osascript (no external dependency).

Every command is wrapped with || echo "[warn] ..." so a single failure logs a warning and the chain continues — cleanup and the notification are never skipped.

On sudo — intentionally NOT enabled

Some casks (e.g. charles, virtualbox) need sudo to upgrade. Granting a background launchd job passwordless sudo would mean adding a NOPASSWD rule to /etc/sudoers, which widens your attack surface.

This project does not do that. Such casks are simply listed in EXCLUDE_CASKS and left for you to upgrade manually:

sudo brew upgrade --cask charles virtualbox

This tool never touches /etc/sudoers and never runs sudo.


Install

git clone https://github.com/ChrisOr-Dev/brew-daily-autoupdate.git
cd brew-daily-autoupdate
./install.sh

install.sh copies the wrapper to ~/Library/Application Support/brew-daily-autoupdate/, renders the launchd plist with absolute paths, and loads the agent. Apple Silicon (/opt/homebrew) and Intel (/usr/local) prefixes are both detected automatically.

Verify

launchctl print "gui/$(id -u)/com.github.chrisor-dev.brew-daily-autoupdate" | grep -i state
tail -f ~/Library/Logs/brew-daily-autoupdate/com.github.chrisor-dev.brew-daily-autoupdate.log

Run once now (manual test)

~/Library/Application\ Support/brew-daily-autoupdate/brew_autoupdate

(Tip: delete ~/Library/Application Support/brew-daily-autoupdate/last_run_date first if you already ran today and want to force a fresh run.)


Configure

Edit EXCLUDE_CASKS at the top of the installed wrapper (~/Library/Application Support/brew-daily-autoupdate/brew_autoupdate). It is a pipe-separated, whole-line match:

EXCLUDE_CASKS='charles|virtualbox|screaming-frog-seo-spider'

Reasons you might exclude a cask:

  • it requires sudo (cannot upgrade in a headless launchd job), or
  • its upstream checksum drifts and repeatedly fails SHA-256 verification.

To change the schedule, edit the StartCalendarInterval block in ~/Library/LaunchAgents/com.github.chrisor-dev.brew-daily-autoupdate.plist, then re-run ./install.sh (or launchctl bootout + bootstrap).


Uninstall

./uninstall.sh

This unloads and removes the launchd agent. Logs and the wrapper directory are left in place; delete them manually if you want a clean sweep.


Requirements

  • macOS (tested on Apple Silicon)
  • Homebrew

No taps, no extra packages, no sudo.


License

MIT — see LICENSE.

About

Daily Homebrew auto-update via launchd — reliable on sleep/shutdown, fault-tolerant, no passwordless sudo

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages