-
Notifications
You must be signed in to change notification settings - Fork 14
/
tunnel.sh
41 lines (31 loc) · 1.76 KB
/
tunnel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
trap ctrl_c INT
function ctrl_c() {
echo "Termination caught. Reverting basic-wordpress to defaults:"
docker exec -ti basic-wordpress wp option set home https://basic.wordpress.test
docker exec -ti basic-wordpress wp option set siteurl https:/basic.wordpress.test
docker exec -ti basic-wordpress wp search-replace "$CF_TUNNEL_PUBLIC_URL" 'https://basic.wordpress.test'
echo "basic-wordpress restored to defaults. Stopping Cloudflare tunnel."
docker stop $CF_TUNNEL_HASH
echo "Done. Enjoy."
exit 0
}
if docker ps | grep basic-wordpress; then
echo "basic-wordpress seems to be running. Proceeding."
else
echo "Can't detect basic-wordpress container running. Aborting."
exit 1
fi
CF_TUNNEL_HASH=$(docker run -d cloudflare/cloudflared:latest tunnel --url https://host.docker.internal:443 --no-tls-verify --http-host-header basic.wordpress.test --origin-server-name basic.wordpress.test)
echo "Cloudflare docker container hash: $CF_TUNNEL_HASH"
echo "Waiting 5 seconds to retrieve your public url."
sleep 5
CF_TUNNEL_PUBLIC_URL=$(docker logs $CF_TUNNEL_HASH 2>&1 | grep -E 'INF[ \|]+https' | grep -oE 'https://[^ ]+')
echo "Performing replacements in the docker basic-wordpress container:"
docker exec -ti basic-wordpress wp option set home $CF_TUNNEL_PUBLIC_URL
docker exec -ti basic-wordpress wp option set siteurl $CF_TUNNEL_PUBLIC_URL
docker exec -ti basic-wordpress wp search-replace 'https://basic.wordpress.test' "$CF_TUNNEL_PUBLIC_URL"
echo
echo "Tunnel is set up. You can reach your site at $CF_TUNNEL_PUBLIC_URL"
echo "Please be aware that your are granting public access to a part of your machine. Do not keep this tunnel running for too long."
echo "Press CTRL + C to revert your site to basic.wordpress.test and exit the tunnel."
while true; do sleep 60; done