Last active
November 17, 2020 23:50
-
-
Save noplanman/eb360d6e82ec0d58a9da884bd4b279d1 to your computer and use it in GitHub Desktop.
Upgrade nghttp2 for brew with a fix for older MacOS versions
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
#!/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 🎉" |
Hi, with the latest version (nghttp2-1.40.0), there is an additional location requiring the same change:
sed -ibkp 's/return dconn;/return std::move(dconn);/g'
"${FOLDERNAME}/src/shrpx_downstream_connection_pool.cc"
After this (along-side the change in shrpx_client_handler), the package compiles.
Best,
Akshat
Thanks for pointing that out @ak9, I've not had any problem compiling though, even though shrpx_downstream_connection_pool.cc
has had that line since forever.
Anyway, should it have caused problems for anyone, should be fixed now.
Thanks this worked for me too (10.11.6), appreciate your work!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks :) worked for me with 10.12.5