-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·79 lines (64 loc) · 2.04 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·79 lines (64 loc) · 2.04 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
#!/bin/bash
set -e
timestamp() {
date +"%Y/%m/%d %H:%M:%S"
}
# Define working and output directories
WORKDIR="$(pwd)"
OUTPUT_DIR="${OUTPUT_DIR:-$WORKDIR/dist}"
# Ensure output dir exists
mkdir -p "$OUTPUT_DIR"
# List of modules to build
MODULES=(
core
social
cookies
tracking
annoyances
german
dns
)
# Determine compiler command (global binary or npx fallback)
if command -v hostlist-compiler >/dev/null 2>&1; then
COMPILER_CMD="hostlist-compiler"
else
COMPILER_CMD="npx --yes @adguard/hostlist-compiler"
fi
echo "[+] Using compiler: $COMPILER_CMD"
# Build each module
for module in "${MODULES[@]}"; do
echo "[+] Compiling lostad_${module}.txt..."
$COMPILER_CMD -c "lostad_${module}.json" -o "lostad_${module}.txt"
done
# Build full list (depends on the individual compiled txt modules)
echo "[+] Compiling lostad_full.txt..."
$COMPILER_CMD -c "lostad_full.json" -o "lostad_full.txt"
# Clean metadata and perform operations for all lists (modules + full list)
for module in "${MODULES[@]}" full; do
echo "[+] Cleaning and finalizing lostad_${module}.txt..."
sort -o "lostad_${module}.txt"{,}
sed -i '/^[[:space:]]*$/d' "lostad_${module}.txt"
sed -i '/^!/d' "lostad_${module}.txt"
sed -i '/^\[Adblock/d' "lostad_${module}.txt"
# DNS Cleanup (Remove cosmetic and modifier rules from imported files like customs)
if [ "$module" = "dns" ]; then
sed -i '/#/d' "lostad_${module}.txt"
sed -i '/\$/d' "lostad_${module}.txt"
sed -i '/=/d' "lostad_${module}.txt"
fi
# Metadata Insertion
sed -i "1i [Adblock Plus 2.0]\n! Title: LostAd ${module^}\n! Expires: 1 days" "lostad_${module}.txt"
done
# Copy artifacts to output dir
echo "[+] Deploying to $OUTPUT_DIR..."
cp lostad_*.txt "$OUTPUT_DIR"/
cp install.html "$OUTPUT_DIR"/
cp install.html "$OUTPUT_DIR"/index.html
if [ -f CNAME ]; then
cp CNAME "$OUTPUT_DIR"/
fi
# Clean up working directory .txt files if OUTPUT_DIR is different from WORKDIR
if [ "$OUTPUT_DIR" != "$WORKDIR" ]; then
rm -f lostad_*.txt
fi
echo "[✓] Done! Built and ready in $OUTPUT_DIR at $(timestamp) UTC"