#!/usr/bin/env bash # Usage: {script} TLD_FILENAME # Update list of TLD set -euo pipefail declare -r IFS=$'\n' declare -r URL="https://data.iana.org/TLD/tlds-alpha-by-domain.txt" declare -r TEMPORARY_LIST_FILE=$(mktemp) declare -r TEMPORARY_RULE_FILE=$(mktemp) declare -r TLD_FILENAME="${1}" echo "Downloading '${URL}'" curl -s -L "${URL}" -o "${TEMPORARY_LIST_FILE}" echo "Updating '${TLD_FILENAME}'" { sed -nE '/^ "${TEMPORARY_RULE_FILE}" mv "${TEMPORARY_RULE_FILE}" "${TLD_FILENAME}"