-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdate_tlds.sh
More file actions
executable file
·84 lines (69 loc) · 2.27 KB
/
Copy pathupdate_tlds.sh
File metadata and controls
executable file
·84 lines (69 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
set -euo pipefail
# Check if the script is being run from the project root
check_run_from_project_root() {
local script_name=$(basename "$0")
if [[ "$0" != "./scripts/$script_name" && "$0" != "scripts/$script_name" ]]; then
echo "Error: This script should be run from the project root as:"
echo " ./scripts/$script_name"
echo ""
echo "Current run path: $0"
exit 1
fi
}
# Check script is run from project root
check_run_from_project_root
# Get the absolute path to the project root directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT" || { echo "Error: Failed to change to project root directory: $PROJECT_ROOT"; exit 1; }
OUTPUT_FILE="data/tlds.php"
temp_file=$(mktemp)
trap 'rm -f "$temp_file"' EXIT
echo "Downloading TLD list from IANA..."
curl -sSL http://data.iana.org/TLD/tlds-alpha-by-domain.txt > "$temp_file"
# Count TLDs (excluding header line)
tld_count=$(tail -n +2 "$temp_file" | wc -l | tr -d ' ')
current_date=$(date +%Y-%m-%d)
echo "Generating $OUTPUT_FILE with $tld_count TLDs..."
# Generate PHP file header
cat > "$OUTPUT_FILE" << HEADER
<?php
/**
* Top Level Domains list from IANA
*
* Updated on $current_date - $tld_count TLDs
* Source: http://data.iana.org/TLD/tlds-alpha-by-domain.txt
*
* Do not edit manually - use scripts/update_tlds.sh to regenerate
*/
return [
'tlds' => [
HEADER
# Convert TLDs to PHP array format (lowercase, quoted, wrapped at ~75 chars)
tail -n +2 "$temp_file" | tr '[:upper:]' '[:lower:]' | \
awk '{printf "'\''%s'\'', ", $0}' | \
fold -s -w 75 | \
sed -e 's/^/ /g' >> "$OUTPUT_FILE"
# Add closing bracket and special TLDs
cat >> "$OUTPUT_FILE" << 'FOOTER'
],
// IETF/ICANN reserved special-use TLDs (not delegated by IANA)
'special' => [
// RFC 2606 - testing and documentation
'test',
'example',
'invalid',
'localhost',
// RFC 6762 - multicast DNS
'local',
// RFC 7686 - Tor hidden services
'onion',
// RFC 9476 - alternative DNS namespaces
'alt',
// ICANN reserved 2024 - private-use applications
'internal',
],
];
FOOTER
echo "Successfully updated $OUTPUT_FILE"