Last active
November 6, 2024 09:59
-
-
Save TechPreacher/e8b7c8aad97022f1bd1af2de47ef8dc3 to your computer and use it in GitHub Desktop.
MacOS Update script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Update brew | |
| echo "🍺 Updating Homebrew formulas and casks" | |
| echo | |
| brew update | |
| brew upgrade | |
| brew upgrade --cask | |
| echo | |
| # Update pipx packages | |
| echo "📦 Updating pipx packages" | |
| echo | |
| # Get the list of installed pipx packages | |
| pipx_json_data=$(pipx list --json) | |
| pipx_packages=$(echo "$pipx_json_data" | jq -r '.venvs[] | .metadata.main_package.apps | .[]' | sort -u) | |
| # Loop through each package and upgrade it | |
| for pipx_package in $pipx_packages; do | |
| pipx_package_name="${pipx_package%% *}" | |
| echo "Upgrading $pipx_package_name..." | |
| pipx upgrade $pipx_package_name | |
| echo | |
| done | |
| # Update python packages | |
| echo "🐍 Updating Python packages" | |
| echo | |
| # Ensure pyenv is initialized in the shell environment | |
| if command -v pyenv 1>/dev/null 2>&1; then | |
| eval "$(pyenv init -)" | |
| fi | |
| # Get all installed Python versions | |
| pyenv_versions=$(pyenv versions --bare) | |
| # Loop through each installed Python version | |
| for pyenv_version in $pyenv_versions; do | |
| echo "Updating packages for Python $pyenv_version" | |
| echo | |
| # Set the local pyenv Python version | |
| pyenv shell $pyenv_version | |
| # Upgrade pip itself | |
| pip install --upgrade pip | |
| # List all installed packages and upgrade them | |
| pip list --outdated --format=json | jq -r '.[] | "\(.name)==\(.latest_version)"' | xargs -n1 pip3 install -U | |
| echo | |
| done | |
| # Reset pyenv version to default | |
| pyenv shell --unset | |
| echo "✨ All done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment