-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_local.sh
executable file
·42 lines (35 loc) · 913 Bytes
/
gen_local.sh
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
#!/bin/sh
CURRENTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd $CURRENTDIR
inport='LocalDNS.md'
tmpout='LocalDNS.tmp'
sed -En "3,$ p" "$inport" | cut -f3,4 -d'|' | sed -En "s|\s||g; s/\|/\n/g p" | grep -E [^[:space:]] | sed -En "s|^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)(:[0-9]+)?$|\1/32|; s|^\[(.+)\](:[0-9]+)?$|\1/128|; p" > "$tmpout"
clashout='LocalDNS.yml'
singout='LocalDNS.json'
# clash
cat << EOF > "$clashout"
# ipcidr
# Source: https://github.com/muink/dns-collection/blob/master/LocalDNS.yml
# Last Modified: `date -u '+%F %T %Z'`
payload:
EOF
cat "$tmpout" | sed -E "s|^| - '|; s|$|'|" >> "$clashout"
echo >> "$clashout"
# sing-box
cat <<-EOF > "$singout"
{
"version": 1,
"rules": [
{
"ip_cidr": [
EOF
sed -En 's|^| "|; s|$|",|; p' "$tmpout" >> "$singout"
sed -i '${s|,$||}' "$singout"
cat <<-EOF >> "$singout"
]
}
]
}
EOF
# cleanup
rm -f "$tmpout"