woocommerce-paypal-payments/.ddev/bin/share
2026-01-19 12:56:19 +01:00

30 lines
871 B
Bash
Executable file

#!/usr/bin/env bash
pkill -f ngrok 2>/dev/null || true
PROJECT_HOST=$(ddev describe -j | jq -r '.raw.hostnames[0]')
ddev share >/dev/null &
NGROK_PID=$!
ngrok-url(){
curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url | awk -F'^http[s]?://' '{print $2}'
}
wp-replace(){
echo "Replacing ${1} with ${2}"
ddev wp search-replace "${1}" "${2}" --all-tables --precise --recurse-objects
}
kill-ngrok(){
echo "Killing ngrok process ${NGROK_PID}"
pkill "${NGROK_PID}"
wp-replace "${NGROK_HOST}" "${PROJECT_HOST}"
}
echo "ngrok started with PID ${NGROK_PID}"
echo "Waiting a few seconds for the service to come up"
sleep 3
NGROK_HOST=$(ngrok-url)
wp-replace "${PROJECT_HOST}" "${NGROK_HOST}"
echo "Your site is now reachable at https://${NGROK_HOST}"
echo "ctrl-c to stop sharing and revert database changes"
trap kill-ngrok INT
wait "${NGROK_PID}"