blob: e778c69f434a86d8362bba64eaf07aa95596da40 (
plain)
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
|
post_install() {
echo -e "\e[1;33m==>\e[0m Read setup instructions at \e[1;36mhttps://wiki.archlinux.org/index.php/Pi-hole\e[0m"
echo -e "\e[1;33m==>\e[0m Generating initial block list, please wait...\e[0m"
chown -R http:http /srv/http/pihole
/opt/pihole/mimic_setupVars.conf.sh
# sed magic to setup /etc/dnsmasq.d/02-pihole.conf and thus protect it from
# getting overwritten by package updates
_dnsmasq_address_setup
# update lists on first run
pihole -g > /dev/null
# setup dns server which by definition modifies /etc/dnsmasq.d/01-pihole.conf
# and thus protects it from getting overwritten by package updates
/usr/bin/pihole -a setdns 8.8.8.8,8.8.4.4 > /dev/null
}
post_upgrade() {
# clean old/unused/deprecated files
[ -e /etc/pihole/hosts ] && rm /etc/pihole/hosts
[ -e /etc/pihole/.useIPv6 ] && rm /etc/pihole/.useIPv6
# if we run _dnsmasq_address_setup now and if the user has modified
# /etc/dnsmasq.d/02-pihole.conf it will be overwritten
#
# pacman will install the sed magic version of this file as
# /etc/dnsmasq.d/02-pihole.pacnew which we do not want on the file system
# so short of changing $dnsmasq_pihole_conf in the _dnsmasq_address_setup
# function, let's just delete it in post_upgrade
#
# users will see pacman output indicating there is a pacnew but I don't
# know an elegant way to provide a script processed config file without
# installing it to a temp file and pointing the sed magic on that temp file
# yet having pacman keep it in the BACKUP array for management to keep it
# from getting overwritten on updates
[ -e /etc/dnsmasq.d/02-pihole.conf.pacnew ] && rm /etc/dnsmasq.d/02-pihole.conf.pacnew
# maybe the KISS solution is simply not to provide
# /etc/dnsmasq.d/02-pihole.conf at all and let the user make it from the wiki
# finally, this shouldn't be the case but keep pacman from throwing errors should
# none of the three checks be true
return 0
}
post_remove() {
# delete all temp files except those modified the user
# TODO - make this more intelligent to save *.pacsave.# where # is a number
find /etc/pihole -type f ! -name '*.pacsave' ! -name 'pihole-FTL.conf' ! -name 'pihole-FTL.db' -delete
}
_dnsmasq_address_setup() { # official code here
. /etc/pihole/setupVars.conf
dnsmasq_pihole_conf=/etc/dnsmasq.d/02-pihole.conf
if [[ -f /etc/hostname ]]; then
hostname=$(</etc/hostname)
elif [ -x "$(command -v hostname)" ]; then
hostname=$(hostname -f)
fi
#Replace IPv4 and IPv6 tokens in 01-pihole.conf for pi.hole resolution.
if [[ "${IPV4_ADDRESS}" != "" ]]; then
tmp=${IPV4_ADDRESS%/*}
sed -i "s/@IPv4@/$tmp/" ${dnsmasq_pihole_conf}
else
sed -i '/^address=\/pi.hole\/@IPv4@/d' ${dnsmasq_pihole_conf}
sed -i '/^address=\/@HOSTNAME@\/@IPv4@/d' ${dnsmasq_pihole_conf}
fi
if [[ "${IPV6_ADDRESS}" != "" ]]; then
sed -i "s/@IPv6@/$IPV6_ADDRESS/" ${dnsmasq_pihole_conf}
else
sed -i '/^address=\/pi.hole\/@IPv6@/d' ${dnsmasq_pihole_conf}
sed -i '/^address=\/@HOSTNAME@\/@IPv6@/d' ${dnsmasq_pihole_conf}
fi
if [[ "${hostname}" != "" ]]; then
sed -i "s/@HOSTNAME@/$hostname/" ${dnsmasq_pihole_conf}
else
sed -i '/^address=\/@HOSTNAME@*/d' ${dnsmasq_pihole_conf}
fi
}
|