#!/usr/bin/env bash set -eu set -o pipefail script_path="$(realpath "$(dirname "$0")")" logfile="/mnt/algo/algo-log-$(date +%s).log" latest_logfile=/mnt/algo/algo-log-latest.log algodir="$(mktemp --tmpdir -d launch-algo.XXXXXXXXXX)" cleanup() { if perl -e'exit 1 unless $ARGV[0] =~ m{^/tmp/launch-algo.*$}' "$algodir"; then rm -rf "$algodir" fi } trap cleanup EXIT touch "$logfile" ln -sf "$(basename "$logfile")" "$latest_logfile" echo "Logging to $latest_logfile" git clone git@github.com:trailofbits/algo "$algodir" cd "$algodir" echo "Installing dependencies..." # shellcheck disable=SC1090 . "${script_path}/algo-virtualenv" >> "$logfile" python -m pip install -r requirements.txt echo "done." rm -f configs/.gitinit rmdir configs mkdir -p .venvs rm -rf /mnt/algo/configs mkdir -p /mnt/algo/configs ln -sf /mnt/algo/configs configs ln -sf "$algodir"/.venvs /mnt/algo/configs/.venvs git apply "${script_path}/algo-config.diff" echo "Running Ansible..." do_token=$(cat /mnt/digitalocean) ansible-playbook main.yml -e "provider=digitalocean server_name=algo.tozt.net region=nyc3 do_token=$do_token dns_adblocking=false ssh_tunneling=false ondemand_cellular=false ondemand_wifi=false" >> "$logfile" "${script_path}/../algo-config" # need to wait for the controlmaster process to exit # XXX there should be a way to tell it to exit, but i don't know how to # calculate the correct controlpath sleep 60 echo "Done"