#!/bin/bash # Function to check the status of the last executed command check_status() { if [ $? -ne 0 ]; then echo "Error: $1 failed." exit 1 fi } # Check if Homebrew is installed if ! command -v brew &>/dev/null; then echo "Error: Homebrew is not installed. Please install Homebrew first." exit 1 fi # Update Homebrew echo "Updating Homebrew..." brew update check_status "brew update" # Upgrade all installed formulae echo "Upgrading installed formulae..." brew upgrade check_status "brew upgrade" # Upgrade all installed casks echo "Upgrading installed casks..." casks=$(brew list --cask) if [ -z "$casks" ]; then echo "No casks installed. Skipping cask upgrades." else for cask in $casks; do echo "Upgrading cask: $cask" brew upgrade --cask "$cask" check_status "brew upgrade --cask $cask" done fi echo "All upgrades completed successfully."