commit e82971ecc3608eb948072793a354c0b534cc8a96 Author: Justin Reichardt Date: Mon Aug 2 16:29:21 2021 -0500 initial setup diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..28401f4 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +dir: + mkdir -p /usr/local/share/removeadhosts +install: dir + cp src/* /usr/local/share/removeadhosts/ + chown -R root:root /usr/local/share/removeadhosts + chmod +x /usr/local/share/removeadhosts/removeadhosts.sh + cp /usr/local/share/removeadhosts/removeadhosts.service /etc/systemd/system/ + cp /usr/local/share/removeadhosts/removeadhosts.timer /etc/systemd/system/ +activate: install + systemctl enable removeadhosts.timer + systemctl start removeadhosts.timer +deactivate: + systemctl disable removeadhosts.timer + systemctl stop removeadhosts.timer +remove: deactivate + rm -f /etc/systemd/system/removeadhosts* + rm -fr /usr/local/share/removeadhosts/ + +reinstall: remove install diff --git a/src/removeadhosts.service b/src/removeadhosts.service new file mode 100644 index 0000000..fc7f7f2 --- /dev/null +++ b/src/removeadhosts.service @@ -0,0 +1,9 @@ +[Unit] +Description=update the hosts file to remove ads + +[Service] +Type=oneshot +ExecStart=/usr/local/share/removeadhosts/removeadhosts.sh + +[Install] +WantedBy=multi-user.target diff --git a/src/removeadhosts.sh b/src/removeadhosts.sh new file mode 100755 index 0000000..dfcd940 --- /dev/null +++ b/src/removeadhosts.sh @@ -0,0 +1,16 @@ +#!/bin/bash +sed -n '1,/# start of removeadhosts/p' /etc/hosts > /tmp/removeadhosts +cat /tmp/removeadhosts | tee /etc/hosts >/dev/null +rm /tmp/removeadhosts +echo "Appended old hosts" +if grep -qinE '# start of removeadhosts' /etc/hosts +then + echo "This has been run before" +else + echo "First Run" + echo '# start of removeadhosts' >> /etc/hosts +fi + +echo 'Downloading ad list' + +curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts 2>/dev/null | tee -a /etc/hosts >/dev/null diff --git a/src/removeadhosts.timer b/src/removeadhosts.timer new file mode 100644 index 0000000..4cedbe4 --- /dev/null +++ b/src/removeadhosts.timer @@ -0,0 +1,10 @@ +[Unit] +Description=update host file to remove ads weekly + +[Timer] +OnBootSec=15min +OnUnitActiveSec=1w +AccuracySec=1s + +[Install] +WantedBy=timers.target