-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·38 lines (33 loc) · 1.36 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
#!/bin/bash
set -e
# This will install dhcp_to_hosts.py to your system.
# Run the following to install directly:
# curl -sSL https://raw.githubusercontent.com/npwolf/pi-hole-dhcp-to-hosts/master/install.sh | sudo bash
PROGRAM="dhcp_to_hosts.py"
DESTINATION="/usr/local/bin/${PROGRAM}"
# Send last run output to this log
LOG_FILE="/var/log/dhcp_to_hosts.log"
DHCP_HOSTS_FILE="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
# We'll setup to run this every 5 minutes via cron
CRONTAB_FREQUENCY='*/5 * * * * '
CRONTAB="# Created by https://github.com/npwolf/pi-hole-dhcp-to-hosts
${CRONTAB_FREQUENCY} root PATH="$PATH:/usr/local/bin" ${DESTINATION} --dhcp_hostsfile ${DHCP_HOSTS_FILE} > ${LOG_FILE} 2>&1"
CRONTAB_FILE="/etc/cron.d/dhcp_to_hosts"
if [[ $EUID -ne 0 ]]; then
echo "ERROR: Run this script with sudo or root."
exit 1
fi
if [ ! -f "${DHCP_HOSTS_FILE}" ]; then
echo "ERROR: Could not find file with dhcp reservations: ${DHCP_HOSTS_FILE}"
echo "You may need to create at least 1 DHCP reservation to create it."
exit 1
fi
echo "Downloading script to ${DESTINATION}"
if curl -sSL --fail "https://raw.githubusercontent.com/npwolf/pi-hole-dhcp-to-hosts/master/${PROGRAM}" -o "${DESTINATION}"; then
chmod a+x "${DESTINATION}"
else
echo "ERROR: Failed to download ${PROGRAM}."
exit 1
fi
echo "Creating crontab ${CRONTAB_FILE}..."
echo "$CRONTAB" > $CRONTAB_FILE