I’ve had a couple of PM’s surrounding divblock.sh
, and some recent posts on the forum.
Back when I adopted divblock
, I wrote a small script to populate the /etc/config/divblock-exclusions
file either from a whitelist file with multiple URL’s to be whitelisted if file path was provided as argument, else falls into interactive mode to allow the user to enter each whitelisted URL individually. On exit it reloads divblock.sh
.
Frankly, I stopped using it after about a month. The number of blocked sites, (from my browsing habits at least) didn’t warrant the cycles needed. Far easier to vi /etc/config/divblock-exclusions
and just append the blocked site to it as needed.
In any event, I’ll put it out for anyone that finds it useful.
- copy it to
/etc/whitelist.sh
- to invoke it
cd /etc
and then./whitelist.sh
- follow the prompts
Summary
#!/bin/ash
# Copyright 2021-2023 RuralRoots GPLv2
# Define output file
output_file="/etc/config/divblock-exclusions"
# Check if file path was provided as argument
if [ $# -eq 1 ] && [ -f "$1" ]; then
batched_whitelist="$1"
printf "\n+++ Reading from batch whitelist file: $batched_whitelist +++\n\n"
# Read each line in the batch input file, escape dots(.), force case to lower, surround URL with "/" delimiter, and write to output file
while read input_url; do
modified_url=$(echo /"$input_url"/ | awk '{print tolower($0)}' | sed 's/\./\\./g')
echo "$modified_url" >> "$output_file"
done < "$batched_whitelist"
printf "\n+++ Finished writing escaped url's to $output_file +++\n\n"
# Cleanup and Exit
rm -r $batched_whitelist
logger -s -t DIVBLOCK:BATCH "reloading divblock.sh on update of $output_file"
/etc/init.d/divblock.sh reload 2> /dev/null
printf "\n+++\t\tD O N E\t\t+++\n\n"
exit
else
printf "\n+++ batch whitelist file not found or no file path provided. Switching to Interactive Mode +++\n\n"
fi
while true; do
echo "Please enter url to whitelist or Done to Stop:"
read input_url
if [ "$input_url" = "Done" ]; then
break
fi
# Escape dots(.) in the input URL, surround it with "/" delimiter, change case to lower, write to ouput file
modified_url="/$(echo "$input_url" | awk '{print tolower($0)}' | sed 's/\./\\./g')/"
# Output the modified url to divblock-exclusions file
echo "$modified_url" >> "$output_file"
done
printf "\n+++ Finished writing escaped url's to $output_file +++\n\n"
# Reload divblock
logger -s -t DIVBLOCK:INTERACTIVE "reloading divblock.sh on update of $output_file"
/etc/init.d/divblock.sh reload 2> /dev/null
printf "\n+++\t\tD O N E\t\t+++\n\n"
exit