#!/usr/bin/env bash


# A better class of script...
set -o errexit          # Exit on most errors (see the manual)
set -o errtrace         # Make sure any error trap is inherited
set -o nounset          # Disallow expansion of unset variables
set -o pipefail         # Use last non-zero exit code in a pipeline
# set -o xtrace          # Trace the execution of the script (debug)

function main() {
  # define source destination path and file names
  readonly S3_BUCKET="s3://gdb-infra-dev-ip-and-domain-block"
  readonly DOMAINS_LIST="IOC_domains_block.txt"
  readonly IP_LIST="IOC_IP_Address_block.txt"
  readonly DST_PATH="/etc/squid"

  # download files from S3
  aws s3 cp ${S3_BUCKET}/${DOMAINS_LIST} ${DST_PATH}/${DOMAINS_LIST}
  aws s3 cp ${S3_BUCKET}/${IP_LIST} ${DST_PATH}/${IP_LIST}

  # restart squid
  systemctl restart squid.service
}

main "$@"
