Skip to content

Commit 7b6b811

Browse files
authored
Update host.sh
1 parent 80c7d9f commit 7b6b811

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

host.sh

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
echo "Clean..."
66
rm -f host adblocker dnsmasq.conf smartdns.conf domain clash allow
77

8+
# Read title file and update placeholders
9+
TITLE_FILE="title"
10+
UPDATED_TITLE=$(<"$TITLE_FILE")
11+
UPDATED_TITLE="${UPDATED_TITLE//PLACEHOLDER_DATE/$(date '+%Y-%m-%d')}"
12+
13+
814

915
# Merge allowlist
1016
echo "Merge allow..."
@@ -60,7 +66,6 @@ rm -f tmpblock
6066

6167

6268
# Check format
63-
6469
echo "Check format..."
6570
sed -E -e '/^[^[:space:]]+\.[^[:space:]]+$/!d' allow
6671
sed -E -e '/^[^[:space:]]+\.[^[:space:]]+$/!d' block
@@ -82,45 +87,46 @@ done < block
8287
mv cleanallow allow
8388
mv cleanblock block
8489

90+
8591
# Generate final lite host list
8692
echo "Merge Combine..."
87-
sort -n block allow allow | uniq -u > tmp && mv tmp tmphost
88-
sort -u tmphost > host
89-
sed -i '/^$/d' host
90-
sed -i s/[[:space:]]//g host
91-
rm -f tmphost
93+
{
94+
echo "$UPDATED_TITLE"
95+
sort -n block allow allow | uniq -u
96+
} > host
97+
98+
99+
# Update placeholder count
100+
DOMAIN_COUNT=$(wc -l < host)
101+
UPDATED_TITLE="${UPDATED_TITLE//PLACEHOLDER_COUNT/$DOMAIN_COUNT}"
102+
sed -i "1,9c$UPDATED_TITLE" host
103+
92104

93105
# Generate different format lists
94106
echo "Adding Compatibility..."
107+
for file in adblocker dnsmasq.conf smartdns.conf domain clash allow; do
108+
echo "$UPDATED_TITLE" > "$file"
109+
cat host >> "$file"
110+
sed -i "1,9c$UPDATED_TITLE" "$file"
111+
done
95112

96-
tee adblocker dnsmasq.conf smartdns.conf domain < host >/dev/null
97113

98114
# Edit adblocker
99-
for file in adblocker ; do
100-
sed -i 's/^/||&/' "$file"
101-
sed -i 's/$/&^/' "$file"
102-
done
115+
sed -i -e '10,$s/^/||&/' -e '10,$s/$/&^/' adblocker
103116

104117
# Edit host
105-
for file in host ; do
106-
sed -i 's/^/0.0.0.0 &/' "$file"
107-
done
118+
sed -i '10,$s/^/0.0.0.0 &/' host
108119

109120
# Edit dnsmasq.conf
110-
for file in dnsmasq.conf ; do
111-
sed -i 's/^/address=\/&/' "$file"
112-
sed -i 's/$/&\/0.0.0.0/' "$file"
113-
done
121+
sed -i -e '10,$s/^/address=\//' -e '10,$s/$/\/0.0.0.0/' dnsmasq.conf
114122

115123
# Edit smartdns.conf
116-
for file in smartdns.conf ; do
117-
sed -i 's/^/address=\/&/' "$file"
118-
sed -i 's/$/&\/#/' "$file"
119-
done
124+
sed -i -e '10,$s/^/address=\//' -e '10,$s/$/\/#/' smartdns.conf
120125

121126
# Generate Clash rules
122-
echo "Adding Clash support..."
123-
sed -e '14i payload:' -e "14,\$s/^/ - '/" -e "14,\$s/$/'/" domain >> clash
127+
sed -i '10i payload:' clash
128+
sed -i "11,\$s/^/ - '/" clash
129+
sed -i "11,\$s/$/'/" clash
124130

125131

126132
# Update README with statistics

0 commit comments

Comments
 (0)