Skip to content

Commit 8746658

Browse files
committed
Add update check
1 parent a4e6950 commit 8746658

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

templates/install-wp-tests.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,40 @@ download() {
3030
fi
3131
}
3232

33+
check_for_updates() {
34+
local remote_url="https://raw.githubusercontent.com/wp-cli/scaffold-command/main/templates/install-wp-tests.sh"
35+
local tmp_script="$TMPDIR/install-wp-tests.sh.latest"
36+
37+
download "$remote_url" "$tmp_script"
38+
39+
if [ ! -f "$tmp_script" ]; then
40+
echo "Warning: Could not download the latest version of the script for update check."
41+
return
42+
fi
43+
44+
local local_hash=""
45+
local remote_hash=""
46+
47+
if command -v shasum > /dev/null; then
48+
local_hash=$(shasum -a 256 "$0" | awk '{print $1}')
49+
remote_hash=$(shasum -a 256 "$tmp_script" | awk '{print $1}')
50+
elif command -v sha256sum > /dev/null; then
51+
local_hash=$(sha256sum "$0" | awk '{print $1}')
52+
remote_hash=$(sha256sum "$tmp_script" | awk '{print $1}')
53+
else
54+
echo "Warning: Could not find shasum or sha256sum to check for script updates."
55+
rm "$tmp_script"
56+
return
57+
fi
58+
59+
rm "$tmp_script"
60+
61+
if [ "$local_hash" != "$remote_hash" ]; then
62+
echo "Warning: A newer version of this script is available at $remote_url"
63+
fi
64+
}
65+
check_for_updates
66+
3367
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
3468
WP_BRANCH=${WP_VERSION%\-*}
3569
WP_TESTS_TAG="branches/$WP_BRANCH"

0 commit comments

Comments
 (0)