Skip to content

0.1.2

Choose a tag to compare

@NetHorror NetHorror released this 09 Dec 14:31
· 26 commits to main since this release
77f4381

This release makes the macOS delayed auto-update script capable of updating ✅ any NetBird installation:

  • 🖥️ GUI/pkg installation (standard .pkg / /Applications/NetBird.app)
  • 🍺 Homebrew installation
  • 🧰 Other CLI-only installs

It also includes 🔁 self-update, 🧾 log retention, and 🔎 robust version detection — similar to the Windows delayed update helper.


✨ Highlights

  • 🧩 Supports all common NetBird install types on macOS

    • Detects whether NetBird is installed via:
      • 🍺 Homebrew (/opt/homebrew/Cellar/netbird/... or /usr/local/Cellar/netbird/...), or
      • 🖥️ standard pkg/app (/Applications/NetBird.app/... symlinked from /usr/local/bin/netbird), or
      • 🧰 “other” / custom locations
    • Chooses the appropriate update mechanism for each type.
  • 🍺 Homebrew-based update (non-root brew call)

    • When netbird comes from Homebrew:
      • 👤 detects the owner user of the brew binary
      • ▶️ runs as that user:
        sudo -u <brew-owner> brew upgrade netbirdio/tap/netbird
        (or brew upgrade netbird if that formula is installed)
      • 🛡️ all executed from a root context while respecting Homebrew permissions.
  • 📦 macOS pkg-based update

    • When netbird is part of /Applications/NetBird.app / system pkg:
      • 🧭 determines the correct pkg URL for the current arch (amd64 or arm64):
        https://pkgs.netbird.io/macos/<arch>
        
      • ⬇️ downloads the latest .pkg into /tmp/netbird.pkg
      • 🛠️ installs it with:
        installer -pkg /tmp/netbird.pkg -target /
      • 🔄 restarts the NetBird service afterwards.
  • 🔁 Script self-update

    • 🏷️ checks the latest GitHub release of NetHorror/netbird-delayed-auto-update-macos
    • 🧮 compares the release tag (X.Y.Z) with SCRIPT_VERSION (0.1.2)
    • If newer:
      • 🧬 tries git pull --ff-only (if the script is in a git checkout)
      • ⬇️ otherwise downloads netbird-delayed-update-macos.sh from the tagged version on raw.githubusercontent.com and overwrites the local script
    • ✅ the updated script is used on the next run.
  • 🧾 Log retention

    • Logs are written to:
      /var/lib/netbird-delayed-update/netbird-delayed-update-*.log
      
    • 🧹 --log-retention-days (default: 60) controls how long logs are kept
    • 🚫 --log-retention-days 0 disables cleanup.
  • ⏳ Version aging / delayed rollout

    • Latest available version becomes a candidate
    • 🕒 Candidate must age for --delay-days days (default: 10) before upgrades are allowed
    • 🧠 State is stored in:
      /var/lib/netbird-delayed-update/state.json
      
    • 🧷 Age calculation is clamped to >= 0 days (no negative values if system time moves backwards)

🧠 How it works (short version)

On each run (manual or via launchd), the script:

  1. 🔎 Resolves netbird and reads the local version:
    netbird version
  2. 🌐 Fetches the latest available version from:
    https://pkgs.netbird.io/releases/latest
    
    and parses the vX.Y.Z tag.
  3. 🧠 Updates state.json with the candidate version and first-seen timestamp.
  4. ⏳ If the candidate is younger than --delay-days → logs that it is still “aging” and exits.
  5. ✅ If the candidate is old enough and newer than the local version:
    • 🧩 detects install type (brew vs pkg/app/other)
    • 🍺 Homebrew: runs brew upgrade … as the brew owner user
    • 📦 pkg/app/other: downloads and installs the latest macOS .pkg directly
  6. 🔄 Stops and restarts the NetBird service around the upgrade.

⚙️ Usage recap

🕒 Install launchd job with defaults:

sudo ./netbird-delayed-update-macos.sh --install

🧰 Install with custom parameters:

sudo ./netbird-delayed-update-macos.sh --install \
  --delay-days 10 \
  --max-random-delay-seconds 3600 \
  --log-retention-days 60 \
  --daily-time "04:00" \
  -r

🧪 Manual one-off run (for testing):

sudo ./netbird-delayed-update-macos.sh \
  --delay-days 0 \
  --max-random-delay-seconds 0 \
  --log-retention-days 60

🗑️ Uninstall the launchd job:

sudo ./netbird-delayed-update-macos.sh --uninstall

🧹 Uninstall and also remove state/logs:

sudo ./netbird-delayed-update-macos.sh --uninstall --remove-state