#!/usr/bin/env bash

set -e;

download_url="https://download-chromium.appspot.com/dl/Linux_x64?type=snapshots";


temp_dir="/tmp/chromium-nightly";

if [[ ! -d "${temp_dir}" ]]; then mkdir "${temp_dir}"; fi

if [[ ! -x "${temp_dir}/chrome-linux/chrome" ]]; then
	echo ">>> Downloading chromium" >&2;

	curl -SL --progress-bar "${download_url}" -o "${temp_dir}/chromium.zip";

	echo ">>> Extracting zip" >&2;

	unzip "${temp_dir}/chromium.zip" -d "${temp_dir}";

	echo ">>> Cleaning up" >&2;

	rm "${temp_dir}/chromium.zip";
fi

echo ">>> Starting chromium" >&2;

exec "${temp_dir}/chrome-linux/chrome" --no-sandbox;