How suryakiran434/brewautomation works
1. Overall shape
This is a macOS automation repository centered on launchd. It has two scheduled workflows: a daily package-update pipeline and a twice-weekly system restart pipeline, plus a timezone watcher that keeps scheduling aligned with local time changes.
2. Main runtime boundary: launchd → shell scripts
The .plist files define how macOS triggers the scripts:
• com.suryakiran.brewauto.plist runs the Homebrew/uv/Python update flow as a user LaunchAgent.
• com.suryakiran.restart.plist runs the reboot flow as a system LaunchDaemon.
• com.suryakiran.tzwatch.plist polls for timezone changes and reloads the brew agent when needed.
This means the orchestration layer is OS-native scheduling, not a long-running app.
3. Brew update pipeline
The update path is split into a guard stage and an execution stage:
• brew_autoupdate.sh checks whether the job already ran today and enforces duplicate prevention via a lock file / stale-lock logic.
• If allowed, it hands off to bubu_executor.sh, which performs the actual upgrades.
This separation is the core boundary between “should we run?” and “do the work.”
4. Package upgrade execution
bubu_executor.sh is the main workhorse. It runs the actual tooling updates:
• brew update
• brew upgrade
• brew upgrade --cask
• uv tool upgrade --all
• uv pip install --upgrade ... for Python packages, using a resolved Python interpreter path
It also handles iTerm2 execution if available, with a background-process fallback if not.
5. Restart pipeline
restart_script.sh handles system restarts and notification around them. For scheduled runs it proceeds without user confirmation; for manual runs it has a short confirmation window unless --force is used. The actual system action is shutdown -r now, so the script is effectively the policy/notification wrapper around a privileged reboot.
6. Notifications as a separate service boundary
notify.py is the email subsystem. It sends HTML and plain-text emails via Gmail SMTP and is used by both the update and restart flows. The README indicates it is responsible for:
• success/failure emails
• HTML escaping of package and metadata fields
• handling SMTP/config/network failures with distinct exit codes
So the repo treats email as a reusable external service client, not as inline shell logic.
7. Configuration and secrets
Runtime configuration comes from a local .env file, which stores sender/recipient email settings and tool paths like BREW_PATH and UV_PATH. The repository hardens this boundary by requiring restrictive file permissions and by passing credentials only in scoped environment variables to child processes, avoiding exposure in process listings.
8. State, locking, and idempotency
The automation maintains local state files and locks in the project directory:
• lock files for duplicate prevention and stale-process detection
• completion markers and logs for daily run tracking
• timezone state files for watcher coordination
The architecture relies on local filesystem state rather than a database or remote queue.
9. Logging and observability
Each flow has dedicated logs, with separate files for automated vs manual runs and for stdout/stderr from launchd. This gives clear diagnostic boundaries:
• brew update logs
• error logs
• skip logs
• restart history logs
• LaunchAgent/LaunchDaemon system logs
The README also indicates log rotation/retention policies, so log files are part of the operational design, not just debugging artifacts.
10. Install/reload tooling
reload.sh and reload_restart.sh are deployment scripts for installing/loading the launchd jobs and preparing permissions/log files. They bridge the repo contents to the macOS runtime locations under ~/Library/LaunchAgents and /Library/LaunchDaemons. In diagram terms, these are the provisioning path from repo checkout to scheduled system automation.
11. Manual triggers share the same execution core
The repo supports manual invocation of the same underlying operations:
• bubu_executor.sh --manual
• restart_script.sh --manual
Manual runs use separate logs and slightly different control flow, but they still rely on the same notification and tool-execution boundaries as the scheduled jobs.
12. External dependencies that materially affect the architecture
The system depends on:
• macOS launchd
• Homebrew
• uv
• Python 3
• Gmail SMTP
• optional iTerm2
• optional pyenv for Python resolution
These are not just tools; they define the runtime environment and failure modes of the automation pipeline.
Main entry points: bubu_executor.sh Update exec · restart_script.sh Reboot policy · notify.py Email service · brew_autoupdate.sh Run guard
Components 19
Orchestration
macOS launchd jobs that trigger the automation on schedules and time-zone changes
- Brew agent · User LaunchAgent that schedules the daily package-update workflow
com.suryakiran.brewauto.plist - Restart daemon · System LaunchDaemon that schedules the twice-weekly reboot workflow
com.suryakiran.restart.plist - TZ watcher · Polling job that watches for timezone changes and realigns scheduling
com.suryakiran.tzwatch.plist
Brew update
Daily package update pipeline and its execution stages
- Run guard · Preflight stage that prevents duplicate daily runs using lock and stale-state checks
brew_autoupdate.sh - Update exec · Main workhorse that performs brew, uv, and Python package upgrades
bubu_executor.sh
Restart
Scheduled reboot workflow and its confirmation policy
- Reboot policy · Handles manual confirmation, scheduled bypass, notification, and the actual reboot action
restart_script.sh
Support
Shared deployment, notification, and local-state boundaries
- Email service · Shared SMTP client for success/failure HTML and text notifications
notify.py - Reload brew · Installs or reloads the brew LaunchAgent and prepares runtime permissions/logs
reload.sh - Reload restart · Installs or reloads the restart LaunchDaemon and its supporting files
reload_restart.sh - TZ reload · Timezone coordination script that triggers a reload when local time changes
tzreload.sh - Local state · Repository-local locks, completion markers, and logs used for idempotency and observability
External
Runtime tools and services the repo depends on
- launchd · Native scheduling runtime that starts agents and daemons
- Homebrew · System package and cask upgrade target
- uv · Used to upgrade uv tools and Python packages
- Python 3 · Interpreter used for the email client and package resolution
- Gmail SMTP · Outbound email transport used by the notifier
- iTerm2 · Optional interactive execution environment for the update flow
- pyenv · Optional Python interpreter resolution fallback
- shutdown · Privileged restart action invoked by the reboot script
Connections 24
- launchd → Brew agent: starts · launchd schedules the daily brew agent
- launchd → Restart daemon: starts · launchd schedules the reboot daemon
- launchd → TZ watcher: starts · launchd runs the timezone watcher
- Brew agent → Run guard: invokes · the agent triggers the duplicate-prevention guard
- Run guard → Update exec: handoff · allowed runs continue into the execution stage
- Update exec → Homebrew: updates · performs brew update and upgrade operations
- Update exec → uv: updates · upgrades uv tools and Python packages
- Update exec → Python 3: runs under · uses a resolved Python interpreter for package management and notifications
- Update exec → iTerm2: uses · prefers iTerm2 for interactive execution when available
- Update exec → pyenv: fallback · can resolve Python through pyenv when needed
- Run guard → Local state: reads/writes · lock files and daily completion state live in the repository-local filesystem
- Update exec → Local state: logs · execution emits dedicated run logs and error output
- Update exec → Email service: reports · success and failure notifications are sent after execution
- Restart daemon → Reboot policy: invokes · the daemon triggers the reboot policy wrapper
- Reboot policy → shutdown: executes · the script performs the actual system reboot
- Reboot policy → Email service: reports · restart completion and failures are emailed through the shared notifier
- Reboot policy → Local state: logs · manual vs scheduled runs and restart history are recorded locally
- TZ watcher → TZ reload: invokes · the watcher script is polled by launchd
- TZ reload → Reload brew: reloads · timezone changes cause the brew agent to be refreshed
- Reload brew → Brew agent: loads · deployment path installs or reloads the brew LaunchAgent
- Reload restart → Restart daemon: loads · deployment path installs or reloads the restart LaunchDaemon
- TZ reload → Local state: tracks · timezone coordination persists local watcher state
- Email service → Gmail SMTP: sends via · email delivery goes through Gmail SMTP
- Email service → Python 3: runs on · the notifier is a Python program