#!/bin/bash
set -e
cp /tmp/nginx-wifi-otantik.conf /etc/nginx/sites-available/wifi-otantik
nginx -t
systemctl reload nginx
# origin local already served; cloudflared token tunnel is already up
systemctl is-active cloudflared
curl -s -o /dev/null -w 'local_app=%{http_code}\n' -H 'Host: app.otantik.cm' http://127.0.0.1/
curl -s -o /dev/null -w 'local_apex=%{http_code}\n' -H 'Host: otantik.cm' http://127.0.0.1/
curl -s -o /dev/null -w 'local_www=%{http_code}\n' -H 'Host: www.otantik.cm' http://127.0.0.1/
echo TUNNEL_OK
