Last active
May 23, 2021 14:02
-
-
Save dive/c4a51179aa96d229a32dd3492e5fdc2d to your computer and use it in GitHub Desktop.
MacPorts installation 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 | |
| set -euf -o pipefail | |
| # FIXME: Check '/opt/local/bin/port' directly if MacPorts is not in the PATH? | |
| if command -v port &> /dev/null; then | |
| printf "%s\n%s\n%s\n" \ | |
| "MacPorts is already installed." \ | |
| "Consider to use 'sudo port selfupdate' command for upgrades." \ | |
| "Check the https://guide.macports.org/#installing.macports.uninstalling to uninstall MacPorts before reinstalling." | |
| exit 0 | |
| fi | |
| TEMP_PKG="$(mktemp -t macports).pkg" | |
| _MACPORTS_LATEST_VERSION="$(curl --silent --url https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL)" | |
| MACPORTS_LATEST_VERSION="${_MACPORTS_LATEST_VERSION##*/v}" | |
| MACOS_VERSION="$(sw_vers -productVersion)" | |
| MACOS_PRODUCT_VERSION="$(cut -d '.' -f 1 <<< "${MACOS_VERSION}")" | |
| # FIXME: There is no reliable way to detect the macOS codename. We can hardcode them or get rid of them | |
| # https://support-sp.apple.com/sp/product?edid=${MACOS_VERSION} does not work as expected and not reliable too for detecting code names | |
| MACPORTS_DOWNLOAD_URL="https://distfiles.macports.org/MacPorts/MacPorts-${MACPORTS_LATEST_VERSION}-${MACOS_PRODUCT_VERSION}-BigSur.pkg" | |
| trap cleanup SIGINT SIGTERM ERR EXIT | |
| cleanup() { | |
| trap - SIGINT SIGTERM ERR EXIT | |
| rm -Rf "${TEMP_PKG}" | |
| } | |
| # Debug # | |
| printf "Temp Path: %s\nMacPorts version: %s\nmacOS version: %s (%s)\nDownload URL: %s\n" \ | |
| "$TEMP_PKG" \ | |
| "$MACPORTS_LATEST_VERSION" \ | |
| "$MACOS_VERSION" \ | |
| "$MACOS_PRODUCT_VERSION" \ | |
| "$MACPORTS_DOWNLOAD_URL" | |
| # End of Debug # | |
| curl --output "${TEMP_PKG}" --remote-name "${MACPORTS_DOWNLOAD_URL}" | |
| sudo installer -verbose -package "${TEMP_PKG}" -target / |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From the discussion (macports-dev -- MacPorts developer discussion).
You can use the following command to check the script (runs the latest revision):
/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/dive/c4a51179aa96d229a32dd3492e5fdc2d/raw/install_macports.sh)"So far, I use the following piece of code to install MacPorts and the packages I need:
Todo
portis already installed and suggest using thesudo port -v selfupdatecommand or uninstall firstsudo port selfupdateafter the installation?$PATHfor shells?Problems
PATHwas not modified as expected forzshExamples
Installation example with the
-storeoption for theinstaller: