Last active
April 9, 2020 22:23
-
-
Save trepmal/6465ff02e11374bb7a3f0b14a82a3acb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Call this file with the URL to test for as the only param | |
# `bash testurl.sh ms.test/doesthissiteexist` | |
# | |
# This script also assumes the multisite you're looking in is at /srv/www/ms | |
# | |
colorreset="\033[0;0m" | |
coloryellow="\033[1;33m" | |
colorred="\033[1;31m" | |
test_url=$1 | |
test_url_protocol="$(echo $test_url | grep :// | sed -e's,^\(.*://\).*,\1,g')" | |
test_url=${test_url#"$test_url_protocol"} | |
domain=$(echo $test_url | cut -f1 -d/) | |
path=$(echo $test_url | cut -f2 -d/) | |
echo "Testing if $test_url is valid..." | |
echo '' | |
echo ': method one :' | |
echo ' compare output to input ' | |
sitefound=$(wp option get siteurl --url="$test_url" --path=/srv/www/ms) | |
sitefound_protocol="$(echo $sitefound | grep :// | sed -e's,^\(.*://\).*,\1,g')" | |
sitefound=${sitefound#"$sitefound_protocol"} | |
if [ $test_url = $sitefound ]; then | |
echo -e $coloryellow'Match! Site is valid'$colorreset | |
else | |
echo -e $colorred'Site is invalid'$colorreset | |
fi | |
echo '--- done ---' | |
echo '' | |
echo ': method two :' | |
echo ' theory only, due to current bug in wp-cli' | |
echo ' https://github.com/wp-cli/entity-command/issues/285' | |
echo ' could eventually query directly for domain+path combo' | |
echo '' | |
echo 'see path flag conflict:' | |
echo wp site list --domain=$domain --path=$path --path=/srv/www/ms | |
echo '--- done ---' | |
echo '' | |
echo ': method three :' | |
echo ' like method 2, but grepping for path instead' | |
match=$(wp site list --domain=$domain --fields=path --format=yaml --path=/srv/www/ms | grep "path: /$path/") | |
if [ ! -z "$match" ]; then | |
echo -e $coloryellow'Match! Site is valid'$colorreset | |
else | |
echo -e $colorred'Site is invalid'$colorreset | |
fi | |
echo '--- done ---' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment