#!/usr/bin/env bash # Update brew repo. printf "%s" "Updating brew repo..." brew update &> /dev/null echo "✅" # Get the currently installed and new version of nghttp2. printf "%s" "Fetch installed and stable nghttp2 versions..." VERSION_INSTALLED="$(brew list --versions | grep nghttp2 | awk '{print $2}')" VERSION_STABLE="$(brew info --json=v1 nghttp2 | sed -E -e 's/.*"stable":"([^"]*).*/\1/')" echo "✅" if [ "$VERSION_STABLE" = "$VERSION_INSTALLED" ]; then echo "Latest version (${VERSION_STABLE}) seems to be installed already!"; read -r -p "Continue anyway? (Y/n): " REPLY case "${REPLY:-y}" in [yY] | [yY][Ee][Ss] ) ;; *) echo "Cancelled ❌"; exit; ;; esac fi if [ -z "$VERSION_INSTALLED" ]; then echo "nghttp2 doesn't seem to be installed. Installing version ${VERSION_STABLE} now."; fi FILENAME="nghttp2--${VERSION_STABLE}.tar.xz" FOLDERNAME="nghttp2-${VERSION_STABLE}" FORMULAFILE="$(brew formula nghttp2)" # Download the package. printf "%s" "Downloading latest version of nghttp2 (${VERSION_STABLE})..." brew fetch nghttp2 &> /dev/null echo "✅" # Change into the Homebrew cache folder. cd "$(brew --cache)" # Extract the archive. printf "%s" "Extract the archive..." tar xJf "${FILENAME}" echo "✅" # Apply the code changes from https://github.com/nghttp2/nghttp2/pull/1319 printf "%s" "Apply code fix..." sed -ibkp 's/return dconn;/return std::move(dconn);/g' \ "${FOLDERNAME}/src/shrpx_client_handler.cc" \ "${FOLDERNAME}/src/shrpx_downstream_connection_pool.cc" echo "✅" # Compress the files to an archive and replace the original one. printf "%s" "Create new archive..." tar cJf ${FILENAME} ${FOLDERNAME} &> /dev/null echo "✅" # Get the checksum of the new archive. SHASUM="$(sha256sum ${FILENAME} | awk '{print $1}')" # Enter the new checksum in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/nghttp2.rb printf "%s" "Inject new checksum..." sed -ibkp "s/sha256 \".*\"$/sha256 \"${SHASUM}\"/g" \ "${FORMULAFILE}" echo "✅" # Install / Upgrade nghttp2. ACTION=upgrade if [ -z "$VERSION_INSTALLED" ]; then ACTION=install fi printf "%s" "Starting nghttp2 ${VERSION_STABLE} ${ACTION}..." brew $ACTION nghttp2 &> /dev/null echo "✅" # Reset the formula to prevent any repo update issues. printf "%s" "Reset formula file..." (cd "$(dirname $(brew formula nghttp2))" && git checkout "${FORMULAFILE}") &> /dev/null echo "✅" echo "All done 🎉"