You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/misc/blocklists/append_ipv4.sh

25 lines
472 B
Bash

#!/usr/bin/env bash
set -euo pipefail;
LIST_FILE="$(dirname "$0")/ipv4.txt";
TMP_FILE="$(mktemp)";
IP_REGEX='(?<!\d)\d+(\.\d+){3}(/\d+)?(?!\d)';
cat "$LIST_FILE" "$@" |
grep --only-matching --perl-regexp "$IP_REGEX" |
sort --version-sort |
uniq > "$TMP_FILE";
echo "$TMP_FILE";
if diff "$LIST_FILE" "$TMP_FILE"; then
echo "No differences found!";
exit 0;
fi
echo "Press enter to approve changes, ^C to abort";
read;
mv "$TMP_FILE" "$LIST_FILE";