#!/bin/bash set -euo pipefail cd "$(dirname "$0")" if [[ ! -f config ]]; then read -p 'Server URL (e.g. `https://mattermost.example.com`): ' MATTERMOST_REMOTE echo "MATTERMOST_REMOTE='${MATTERMOST_REMOTE//\//}'" > config echo 'You can change this later by editing the file `config`.' fi source "config" server_pid=0 finish() { if [[ $server_pid -gt 1 ]]; then kill "$server_pid" || true; server_pid=0; fi } trap finish EXIT python3 -m "http.server" >/dev/null 2>&1 & mitmproxy -s etc/mitm_cors.py -m "reverse:$MATTERMOST_REMOTE"