Skip to content
Snippets Groups Projects
addPatchToNginxSpec.sh 1022 B
Newer Older
  • Learn to ignore specific revisions
  • Luca Bassi's avatar
    Luca Bassi committed
    #!/usr/bin/env bash
    
    set -ex
    
    # Add the httpg patch
    # Set the nginx spec file with the httpg patch
    PATCH_NAME="nginx-httpg_no_delegation.patch"
    SPEC_FILE="${HOME}/rpmbuild/SPECS/nginx.spec"
    # Copy the patch in the rpmbuild directory
    cp ${CI_PROJECT_DIR}/${PATCH_NAME} ~/rpmbuild/SOURCES/
    cd ~/rpmbuild/SOURCES/
    # Find the highest existing Patch number in the spec file
    LAST_PATCH_NUM=$(grep -oP "^Patch\K[0-9]+" $SPEC_FILE | sort -n | tail -1)
    if [ -z "$LAST_PATCH_NUM" ]; then
      # There are no existing patches: find the highest Source number in the spec file
      LAST_SOURCE_NUM=$(grep -oP "^Source\K[0-9]+" $SPEC_FILE | sort -n | tail -1)
      # Add the patch to the spec file after the last Source
      sed -i "/^Source${LAST_SOURCE_NUM}/a Patch0: ${PATCH_NAME}" "${SPEC_FILE}"
    else
      # Add the new patch to the spec file after the last Patch
      sed -i "/^Patch${LAST_PATCH_NUM}/a Patch$((LAST_PATCH_NUM + 1)): ${PATCH_NAME}" "${SPEC_FILE}"
    fi
    # Add httpg to release
    sed -i '/%define base_release/ s/ngx/httpg/' "${SPEC_FILE}"