Skip to content

Instantly share code, notes, and snippets.

@noplanman
Last active November 17, 2020 23:50
Show Gist options
  • Select an option

  • Save noplanman/eb360d6e82ec0d58a9da884bd4b279d1 to your computer and use it in GitHub Desktop.

Select an option

Save noplanman/eb360d6e82ec0d58a9da884bd4b279d1 to your computer and use it in GitHub Desktop.

Revisions

  1. noplanman revised this gist Apr 6, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion upgrade-nghttp2
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,8 @@ 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_client_handler.cc" \
    "${FOLDERNAME}/src/shrpx_downstream_connection_pool.cc"
    echo ""

    # Compress the files to an archive and replace the original one.
  2. noplanman revised this gist Sep 10, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion upgrade-nghttp2
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,11 @@ echo "✅"

    if [ "$VERSION_STABLE" = "$VERSION_INSTALLED" ]; then
    echo "Latest version (${VERSION_STABLE}) seems to be installed already!";
    exit;
    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
  3. noplanman revised this gist Aug 16, 2019. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions upgrade-nghttp2
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ echo "✅"

    # Get the currently installed and new version of nghttp2.
    printf "%s" "Fetch installed and stable nghttp2 versions..."
    VERSION_INSTALLED="$(brew list --versions | grep nghttp22 | awk '{print $2}')"
    VERSION_INSTALLED="$(brew list --versions | grep nghttp2 | awk '{print $2}')"
    VERSION_STABLE="$(brew info --json=v1 nghttp2 | sed -E -e 's/.*"stable":"([^"]*).*/\1/')"
    echo ""

    @@ -58,7 +58,13 @@ sed -ibkp "s/sha256 \".*\"$/sha256 \"${SHASUM}\"/g" \
    echo ""

    # Install / Upgrade nghttp2.
    brew install 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..."
  4. noplanman created this gist Jun 21, 2019.
    68 changes: 68 additions & 0 deletions upgrade-nghttp2
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #!/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 nghttp22 | 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!";
    exit;
    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"
    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.
    brew install nghttp2

    # 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 🎉"