-
Notifications
You must be signed in to change notification settings - Fork 7
/
pihole_static_sort
executable file
·48 lines (35 loc) · 1.44 KB
/
pihole_static_sort
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
#!/bin/bash
###########################################################################
# pihole_static_sort
# Sorts the dnsmasq configuration file used by Pi-hole's DHCP server
# for static DHCP reservations.
# Version 1.1 - Jan 15, 2019 - Steve Jenkins (stevejenkins.com)
# USAGE
# Run ./pihole_static_sort from the command line
###########################################################################
# Constants
dnsmasq_dir='/etc/dnsmasq.d'
static_file='04-pihole-static-dhcp.conf'
# Only used for debugging
# set -x
# Backup original static file and make working copy
printf "\nBacking up $dnsmasq_dir/$static_file to /tmp...\n"
cp $dnsmasq_dir/$static_file /tmp/$static_file.orig
cp $dnsmasq_dir/$static_file /tmp
# Sort working copy
printf "\nSorting static DHCP entries:\n"
#sort -u -n -t, -k2V /tmp/$static_file | tr '[:upper:]' '[:lower:]' > /tmp/$static_file.sort
sort -u -n -t, -k2V /tmp/$static_file > /tmp/$static_file.sort
# Display entry counts
orig_file_count="$(wc -l < /tmp/$static_file.orig)"
sort_file_count="$(wc -l < /tmp/$static_file.sort)"
printf "$orig_file_count original entries!\n$sort_file_count sorted entries!\n"
# Copy sorted file to original location
printf "\nWriting sorted entries to $dnsmasq_dir/$static_file...\n"
sudo cp -f /tmp/$static_file.sort $dnsmasq_dir/$static_file
# Restarting pihole-FTL service
printf "\nRestarting pihole-FTL service...\n"
sudo service pihole-FTL restart
# All done!
printf "\nDone!\n"
exit