Asked my friend to write really simple, setup and forget script. No settings, no nothing.
(Yes she allowed me to publish it here)
Script for geeks
#!/bin/sh
hosts_url="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
hosts_file="/tmp/adblock-hosts"
update_script_path="/usr/bin/update_hosts.sh"
dnsmasq_conf="/etc/dnsmasq.conf"
if ! which wget >/dev/null 2>&1; then
echo "wget is not installed. Installing..."
opkg update
opkg install wget
if [ $? -ne 0 ]; then
echo "Error installing wget. Please check your internet connection and try again."
exit 1
fi
echo "wget installed successfully."
else
echo "wget is already installed."
fi
cat <<EOF > "$update_script_path"
#!/bin/sh
wget -q -O "$hosts_file" "$hosts_url"
EOF
chmod +x "$update_script_path"
if ! grep -q "addn-hosts=$hosts_file" "$dnsmasq_conf"; then
echo "addn-hosts=$hosts_file" >> "$dnsmasq_conf"
/etc/init.d/dnsmasq restart
fi
(crontab -l 2>/dev/null; echo "@reboot $update_script_path"; echo "0 0 * * * $update_script_path") | crontab -
rm "/tmp/setup_hosts.sh"
echo "Hosts update setup complete and self-removal successful."
echo "The update script is located at: $update_script_path (persistent)"
echo "It will run on reboot and at midnight."
echo "Additional hosts file is saved in RAM at: $hosts_file"
echo "Dnsmasq configured to use it."
To run it just use this command:
sh <(wget -qO- https://pastebin.com/raw/jrT2JmpN)