Add tool/util [patch-util] - useful only for devs/contributors

This commit is contained in:
xZero707
2021-03-19 19:10:54 +01:00
parent a61b1c90dd
commit 3c7ed3fff5
5 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env sh
set -e
echo "> Building helper image..."
docker build -t local/wp-patch-util .
mkdir wp-src/ -p
echo ""
echo "> Running helper container..."
USER_ID=$(id -u "${USER}")
GROUP_ID=$(id -g "${USER}")
docker run --rm -t --name="wp-patch-util-$(date +%s)" -v "${PWD}/wp-src:/wp/src" -e "UID=${USER_ID}" -e "GID=${GROUP_ID}" local/wp-patch-util
sudo chown "${USER}:${USER}" wp-src -R
echo ""
echo ""
echo "> Two files are now downloaded to wp-src"
echo "> Please update wp-src/mod-update-core.php with code bellow and then execute ./01-create-patch.sh"
echo ""
echo ""
echo "wp_die("
echo " __( 'Sorry, you are not allowed to update this site.' ) ."
echo " ' Click <a href=\"https://github.com/N0rthernL1ghts/wordpress/wiki/WordPress-Core-Updates\">here</a> to learn why.'"
echo ");"
echo ""

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env sh
MOD_FILE="mod-update-core.php"
TARGET_FILE="update-core.php"
PATCH_FILE="update-core.php.patch"
set -e
cd ./wp-src
if [ ! -f "${MOD_FILE}" ]; then
echo "X ${MOD_FILE} not found"
exit 1
fi
if [ ! -f "${TARGET_FILE}" ]; then
echo "X ${TARGET_FILE} not found"
exit 1
fi
if cmp --silent "${MOD_FILE}" "${TARGET_FILE}"; then
echo "X ${MOD_FILE} and ${TARGET_FILE} are the same. Nothing to patch."
exit 1
fi
if [ -f "${PATCH_FILE}" ]; then
PATCH_FILE_BACKUP="$(date +%s)bak-${PATCH_FILE}"
echo "! Patch file ${PATCH_FILE} already exists and will be backed up"
mv "${PATCH_FILE}" "${PATCH_FILE_BACKUP}"
echo "! Backup: ${PATCH_FILE_BACKUP}"
fi
# diff exits with code 1 if there was a difference between files, so we need to temporarily disable exit-on-error
set +e
echo "> Patching file..."
diff -u "${TARGET_FILE}" "${MOD_FILE}" > "${PATCH_FILE}"
set -e
if [ ! -s "${PATCH_FILE}" ]; then
echo "X Patch failed."
exit 1
fi
echo "> Fixing patch header"
sed -i "s/${MOD_FILE}/${TARGET_FILE}/g" "${PATCH_FILE}"
echo "> Patch file created ${PATCH_FILE}"
echo "> Please run: "
echo " cp './wp-src/${PATCH_FILE}' '../../rootfs/etc/wp-mods/wp-admin/'"
echo ""
echo "> Don't forget to commit the changes"
echo "> Finished"

View File

@@ -0,0 +1,13 @@
FROM wordpress:cli-php7.4 AS wordpress-builder
USER root
COPY ["rootfs", "/"]
WORKDIR "/wp"
ENV UID 1000
ENV GID 1000
ENV WP_LOCALE "en_US"
ENV WP_VERSION "5.7.0"
ENTRYPOINT ["/wp/entrypoint.sh"]

View File

@@ -0,0 +1,18 @@
# Patch Helper Utility
This utility is intended for developers/contributors to more painlessly create a patch(es) for core WordPress file(s).
The flow is like this:
```
$ ./00-download-file.sh
# Modify file prefixed with mod-
$ ./01-create-patch.sh
# Copy over finished patch to appropriate location in rootfs/etc/wp-mods
```
Instructions are provided by the scripts.
### Supported patches
- **wp-admin/update-core.php**
Click [here](https://github.com/N0rthernL1ghts/wordpress/wiki/WordPress-Core-Updates) for details.

View File

@@ -0,0 +1,23 @@
#!/usr/bin/env sh
echo "> Downloading WordPress ${WP_VERSION} ..."
# Removes trailing zero if found
WP_SHORT_VERSION=$(echo "${WP_VERSION}" | sed --expression='s/.0//g');
wp --allow-root --path="/tmp" core download --locale="${WP_LOCALE}" --version="${WP_SHORT_VERSION}"
if [ ! -f "/tmp/wp-admin/update-core.php" ]; then
echo "X WordPress download failed"
exit 1
fi
mkdir src -p
rm src/* -f
cp /tmp/wp-admin/update-core.php src/
cp src/update-core.php src/mod-update-core.php
echo "> Files ready."
exit 0