0
0
mirror of https://github.com/tj/n.git synced 2024-11-22 11:37:26 +01:00
n/test/bin/proxy-build
John Gee f1d0dd5a22
Rework activate to support more configurations (#657)
* Rework activate to be (much) more explicit. Add archlinux image. Remove need for rsync.

* Reword use case without npm
2021-03-12 19:41:44 +13:00

50 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Unoffical bash safe mode
set -euo pipefail
BIN_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
waitproxy() {
while ! nc -z localhost 8080 ; do sleep 1 ; done
}
if nc -z localhost 8080; then
echo "Error: port 8080 already in use. Is mitmdump already running?"
pgrep -f -l mitmdump
exit 2
fi
echo "Launching proxy..."
mitmdump -w proxy~~.dump &> /dev/null &
mitm_process="$!"
echo "Waiting for proxy..."
waitproxy
echo "Recording downloads..."
source tests/shared-functions.bash
unset_n_env
setup_tmp_prefix
# Hack curl to avoid certificate issues with proxy
readonly CURL_HOME="$(dirname "${BIN_DIRECTORY}")/config"
export CURL_HOME
# Go through proxy so it can record traffic, http for taobao redirects
http_proxy="$(hostname):8080"
export http_proxy
https_proxy="$(hostname):8080"
export https_proxy
# Need to do wget first, as curl gets compressed index.tab which will break wget.
# linux, archlinux-curl gets gz archives
docker-compose run archlinux-curl /mnt/test/tests/install-reference-versions.bash
# linux, ubuntu-curl would get compressed index and gz archives
docker-compose run ubuntu-wget /mnt/test/tests/install-reference-versions.bash
# native
tests/install-reference-versions.bash
rm -rf "${TMP_PREFIX_DIR}"
echo "Stopping proxy"
kill "${mitm_process}"