#!/bin/bash -e

script/update-cdn-ips >/dev/null 2>&1
files=( cloudflare fastly)

# `git diff --quiet` suppresses output and sets a return code
# 0 - no changes
# 1 - changes
for file in "${files[@]}"
do
  if git diff -w --quiet --cached "config/$file-ips.txt"
  then
    echo "$file IP list is up-to-date."
  else
    echo git reset "config/$file-ips.txt"
    git reset --quiet "config/$file-ips.txt"
    echo "*** $file IP list is out of date! Run script/update-cdn-ips!"
    exit 1
  fi
done
