miker.blog

Updating My Remote Mac

Working remotely means I often need to maintain my Mac from afar. Over time, I've developed a script that makes this task much simpler when I'm logged in via SSH.

My Remote Management Solution

My bash script below helps me keep my Mac maintained and updated when I'm working remotely. It handles all the routine maintenance tasks I'd normally do if I were sitting at my desk.

The Remote Management Script

How It Works

1. Error Handling

The script uses set -euxo pipefail, which is a robust error handling combination in bash:

This means I'll know exactly where things went wrong if there's an issue during remote maintenance.

2. Dependency Check

The script verifies Homebrew's presence with:

This one-liner checks if the brew command exists in the system's PATH, redirecting both standard output and errors to /dev/null. If Homebrew isn't found, it exits with a helpful error message instead of failing mysteriously later.

3. Permissions Management

Two critical permission commands ensure proper Homebrew operation:

This grants the current user full ownership and read-write-execute permissions on the Perl installation directory. The capital X in u+rwX is intentional - it only adds execute permission to directories, not files.

4. Command Execution

The Perl wrapper uses Term::ANSIColor for output formatting and implements a simple but effective command execution pipeline:

5. System Updates

The script runs updates in a specific order:

  1. Homebrew updates:

    • brew update refreshes package lists

    • brew upgrade updates all formulae

    • brew upgrade --cask handles GUI applications

    • brew cleanup removes old versions

    • brew doctor checks system health

    • brew missing finds broken dependencies

  2. Mac App Store updates via mas upgrade -q

    • The -q flag keeps output minimal and clean

  3. System updates using softwareupdate --install --recommended

    • Only installs Apple's recommended updates

    • Avoids beta versions and optional updates

  4. Developer tools with xcode-select --install

    • The 2>/dev/null || true prevents errors if already installed

    • Ensures command line tools stay current

Note: Always review scripts before running them, especially when they use sudo commands or modify system files. This script assumes you have both Homebrew and mas (Mac App Store command line) installed.


This script has made remote management much easier for me. It's nothing fancy, but it gets the job done when I need to keep my Mac up to date from anywhere. I've been using it reliably for months now, tweaking it occasionally as my needs change.