#!/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" if grep --extended-regexp --quiet "^Patch.*: $PATCH_NAME" "$SPEC_FILE"; then >&2 echo "The patch $PATCH_NAME is already included in the spec file $SPEC_FILE" exit 0 fi # Copy the patch in the rpmbuild directory cp ${CI_PROJECT_DIR}/${PATCH_NAME} ~/rpmbuild/SOURCES/ pushd ~/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.backup "/^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.backup "/^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}" diff "${SPEC_FILE}.backup" "${SPEC_FILE}" || true popd