#!/usr/bin/env bash

if [[ -z $1 ]]; then
  echo; echo "Usage: $0 <env>";
  echo; echo;
  exit 1;
fi

SITES=$(terminus org:site:list ohio-state-arts-and-sciences --upstream=b9baf7af-eb2c-4db5-81e6-32d3d9042572 --tag=D8 --fields=name --format=string | sort);
echo $SITES;

parallel --delay 0.1 "./homepage_status.sh {} $1" ::: $SITES



# for f in `terminus org:site:list ohio-state-arts-and-sciences --upstream=b9baf7af-eb2c-4db5-81e6-32d3d9042572 --tag=D8 --fields=name --format=string`; do
#   if [[ ! -z "$1" ]]; then
#     SITE="$1.$f";
#   else
#     SITE="$f";
#   fi

#   #echo -n ".";
#   RESPONSE=`curl -ksSL -w "%{http_code} %{url_effective}" -o /dev/null https://${SITE}`;
#   #echo -n ".";
#   HTTP_CODE=`echo "$RESPONSE" | cut -d' ' -f 1`;
#   URL_EFFECTIVE=`echo "$RESPONSE" | cut -d' ' -f 2`;

#   if [[ "$HTTP_CODE" == "200" ]]; then
#     echo "OK $URL_EFFECTIVE";
#   else
#     echo "######################################";
#     echo "Error: $HTTP_CODE $URL_EFFECTIVE";
#   fi

# done
