improve hostname cleanup
This commit is contained in:
parent
fa6221e91a
commit
f3f4f72d9c
31
get-hosts.sh
31
get-hosts.sh
|
@ -32,6 +32,28 @@ fi
|
||||||
hosts="$hosts1
|
hosts="$hosts1
|
||||||
$hosts2"
|
$hosts2"
|
||||||
|
|
||||||
|
# Prepare temporary file.
|
||||||
|
tempfile=$(mktemp)
|
||||||
|
# Delete temporary file on exit.
|
||||||
|
finish() {
|
||||||
|
rm -f "$tempfile"
|
||||||
|
}
|
||||||
|
trap finish EXIT
|
||||||
|
|
||||||
|
echo "$hosts" | while read -r line; do
|
||||||
|
# Remove redundant ":1965" port from each line that has it.
|
||||||
|
line="${line%:1965}"
|
||||||
|
# Remove redundant "." from the end of each hostname that has it.
|
||||||
|
line="${line%.}"
|
||||||
|
# Hostname to lowercase.
|
||||||
|
line=$(echo "$line" | tr '[:upper:]' '[:lower:]')
|
||||||
|
# Add cleaned up hostnames to temporary file.
|
||||||
|
echo "$line" >> "$tempfile"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Get hosts back from temporary file.
|
||||||
|
hosts=$(cat "$tempfile")
|
||||||
|
|
||||||
# Remove empty lines; convert punycode to unicode; sort entries; remove duplicates.
|
# Remove empty lines; convert punycode to unicode; sort entries; remove duplicates.
|
||||||
hosts=$(echo "$hosts" | awk NF | idn --allow-unassigned --idna-to-unicode | sort -fu)
|
hosts=$(echo "$hosts" | awk NF | idn --allow-unassigned --idna-to-unicode | sort -fu)
|
||||||
|
|
||||||
|
@ -51,16 +73,9 @@ if [ -z "$hosts" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Save to temporary file.
|
# Save to temporary file again.
|
||||||
tempfile=$(mktemp)
|
|
||||||
echo "$hosts" > "$tempfile"
|
echo "$hosts" > "$tempfile"
|
||||||
|
|
||||||
# Delete temporary file on exit.
|
|
||||||
finish() {
|
|
||||||
rm -f "$tempfile"
|
|
||||||
}
|
|
||||||
trap finish EXIT
|
|
||||||
|
|
||||||
# Check connection to host.
|
# Check connection to host.
|
||||||
# $1: "" or "tor"
|
# $1: "" or "tor"
|
||||||
# $2: host[:port]
|
# $2: host[:port]
|
||||||
|
|
Loading…
Reference in New Issue