forked from mmotti/pihole-regex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
56 lines (44 loc) · 1.85 KB
/
install.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# shellcheck disable=SC1117
# Set regex outputs
file_pihole_regex="/etc/pihole/regex.list"
file_mmotti_regex="/etc/pihole/mmottiandicedcomputer-regex.list"
# Restore config prior to previous install
# Keep entries only unique to pihole regex
if [ -s "$file_pihole_regex" ] && [ -s "$file_mmotti_regex" ]; then
echo "[i] Removing mmotti and icedcomputer regex.list from a previous install"
comm -23 <(sort $file_pihole_regex) <(sort $file_mmotti_regex) | sudo tee $file_pihole_regex > /dev/null
sudo rm -f $file_mmotti_regex
fi
# Fetch mmotti regex.list
echo "[i] Fetching mmotti and icedcomputer regex.list"
sudo wget -qO "$file_mmotti_regex" https://raw.githubusercontent.com/poorpocketsmcnewhold/pihole-regex/master/regex.list
# Exit if unable to download list
if [ ! -s "$file_mmotti_regex" ]; then
echo "Error: Unable to fetch mmotti and icedcomputer regex.list"
exit
else
mmotti_regex="$(cat $file_mmotti_regex)"
echo "[i] $(wc -l <<< "$mmotti_regex") regexps found in mmotti and icedcomputer regex.list"
fi
# Check existing configuration
if [ -s "$file_pihole_regex" ]; then
# Extract non mmottiandicedcomputer-regex entries
existing_regex_list="$(cat $file_pihole_regex)"
# Form output (preserving existing config)
echo "[i] $(wc -l <<< "$existing_regex_list") regexps exist outside of mmotti and icedcomputer regex.list"
final_regex=$(printf "%s\n" "$mmotti_regex" "$existing_regex_list")
else
echo "[i] No regex.list differences to mmotti's regex.list"
final_regex=$(printf "%s\n" "$mmotti_regex")
fi
# Output to regex.list
echo "[i] Saving to $file_pihole_regex"
LC_COLLATE=C sort -u <<< "$final_regex" | sudo tee $file_pihole_regex > /dev/null
# Refresh Pi-hole
echo "[i] Refreshing Pi-hole"
sudo killall -SIGHUP pihole-FTL
echo "[i] Done"
# Output to user
echo $'\n'
cat $file_pihole_regex