From 6e78e79fa712772c68d857c780461913a40b8c3b Mon Sep 17 00:00:00 2001
From: xZero707 <xzero@elite7hackers.net>
Date: Thu, 23 Sep 2021 17:44:41 +0200
Subject: [PATCH] Add specify WP_VERSION in arguments

---
 build/patch-util/00-download-file.sh     | 11 +++++++++--
 build/patch-util/Dockerfile              |  3 ++-
 build/patch-util/rootfs/wp/entrypoint.sh |  3 ++-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/build/patch-util/00-download-file.sh b/build/patch-util/00-download-file.sh
index 64400f0..d14f3b7 100755
--- a/build/patch-util/00-download-file.sh
+++ b/build/patch-util/00-download-file.sh
@@ -1,8 +1,15 @@
 #!/usr/bin/env sh
 set -e
 
+WP_VERSION="${1:-}"
+
+if [ -z "${WP_VERSION}" ]; then
+  echo "> Error: WP_VERSION is not specified"
+  exit 1
+fi
+
 echo "> Building helper image..."
-docker build -t local/wp-patch-util .
+docker build --build-arg "WP_VERSION=${WP_VERSION}" -t local/wp-patch-util .
 mkdir wp-src/ -p
 echo ""
 echo "> Running helper container..."
@@ -22,4 +29,4 @@ 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 ""
\ No newline at end of file
+echo ""
diff --git a/build/patch-util/Dockerfile b/build/patch-util/Dockerfile
index 003d216..6e4caec 100644
--- a/build/patch-util/Dockerfile
+++ b/build/patch-util/Dockerfile
@@ -8,6 +8,7 @@ WORKDIR "/wp"
 ENV UID 1000
 ENV GID 1000
 ENV WP_LOCALE "en_US"
-ENV WP_VERSION "5.8.0"
+ARG WP_VERSION "5.8.0"
+ENV WP_VERSION "${WP_VERSION}"
 
 ENTRYPOINT ["/wp/entrypoint.sh"]
diff --git a/build/patch-util/rootfs/wp/entrypoint.sh b/build/patch-util/rootfs/wp/entrypoint.sh
index 0b28f49..860ac77 100755
--- a/build/patch-util/rootfs/wp/entrypoint.sh
+++ b/build/patch-util/rootfs/wp/entrypoint.sh
@@ -4,6 +4,7 @@ echo "> Downloading WordPress ${WP_VERSION} ..."
 
 # Removes trailing zero if found
 WP_SHORT_VERSION=$(echo "${WP_VERSION}" | sed --expression='s/.0//g');
+echo "> Short Version: ${WP_SHORT_VERSION}"
 
 wp --allow-root --path="/tmp" core download --locale="${WP_LOCALE}" --version="${WP_SHORT_VERSION}"
 
@@ -20,4 +21,4 @@ cp src/update-core.php src/mod-update-core.php
 
 echo "> Files ready."
 
-exit 0
\ No newline at end of file
+exit 0