summarylogtreecommitdiffstats
path: root/pi-hole-server.install
blob: 31b1e3c952b29ce01a89590131907cc387031a3b (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
post_install() {
  echo -e "\e[1;33m==>\e[0m Please read configuration instructions at /usr/share/doc/pihole/configuration"
  echo -e "\e[1;33m==>\e[0m or ArchWiki page at \e[1;36mhttps://wiki.archlinux.org/index.php/Pi-hole\e[0m"
  echo -e "\e[1;33m==>\e[0m \e[1;31mVer. 3.1-6\e[0m: dnsmasq conf file is changed"
  echo -e "\e[1;33m==>\e[0m Please follow configuration upgrade steps"
  echo -e "\e[1;33m==>\e[0m Neutrino emissions detected..."
  touch /etc/dnsmasq.d/02-pihole-dhcp.conf
  touch /etc/dnsmasq.d/03-pihole-wildcard.conf
  chown -R http.http /srv/http/pihole
  /opt/pihole/mimic_setupVars.conf.sh

  _dnsmasq_address_setup

  /usr/bin/pihole updateGravity > /dev/null
  /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

  post_install $1
}

post_remove() {
  [ -e /run/log/pihole.log ] && rm /run/log/pihole.log
  [ -e /etc/dnsmasq.d/02-pihole-dhcp.conf ] && rm /etc/dnsmasq.d/02-pihole-dhcp.conf
  [ -e /etc/dnsmasq.d/03-pihole-wildcard.conf ] && rm /etc/dnsmasq.d/03-pihole-wildcard.conf

  # 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
}