From 9da33080744c0bc7bf7eeffe01d30c76fa1b1d96 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 1 Jun 2024 14:02:14 -0500 Subject: [PATCH] Refactor website blocking script and settings configuration --- toggle-website-blocking/run.sh | 58 +++++++++++++++++++++++++-- toggle-website-blocking/settings.conf | 2 +- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/toggle-website-blocking/run.sh b/toggle-website-blocking/run.sh index 87787b0..c0266a4 100755 --- a/toggle-website-blocking/run.sh +++ b/toggle-website-blocking/run.sh @@ -4,7 +4,7 @@ echo "-------------------" echo "BigBearWebsiteBlocker" echo "-------------------" -echo "Here is some links" +echo "Here are some links" echo "https://community.bigbeartechworld.com" echo "https://github.com/BigBearTechWorld" echo "-------------------" @@ -12,8 +12,60 @@ echo "If you would like to support me, please consider buying me a tea" echo "https://ko-fi.com/bigbeartechworld" echo "" -# Load settings from the configuration file -source ./settings.conf +# Set the current directory +CURRENT_DIR=$(dirname "$0") + +# Load settings from the configuration file or create a default one +SETTINGS_FILE="$CURRENT_DIR/settings.conf" +if [[ -f "$SETTINGS_FILE" ]]; then + source "$SETTINGS_FILE" +else + cat < "$SETTINGS_FILE" +HOSTS_FILE="/etc/hosts" +CONFIG_FILE="$CURRENT_DIR/blocked_websites.conf" +DEFAULT_RESOLVER="127.0.0.1" +START_MARKER="# START blocked_websites by BigBearTechWorld" +END_MARKER="# END blocked_websites by BigBearTechWorld" +BACKUP_DIR="/tmp" +EOL + source "$SETTINGS_FILE" + echo "Created default settings.conf file." +fi + +CONFIG_FILE="$CURRENT_DIR/$(basename $CONFIG_FILE)" +# Create a default blocked_websites.conf file if it doesn't exist +if [[ ! -f "$CONFIG_FILE" ]]; then + cat < "$CONFIG_FILE" +x.com +twitter.com +instagram.com +facebook.com +linkedin.com +snapchat.com +tiktok.com +reddit.com +pinterest.com +tumblr.com +flickr.com +quora.com +wechat.com +wechatapp.com +vk.com +ok.ru +viber.com +line.me +telegram.org +whatsapp.com +youtube.com +news.ycombinator.com +nytimes.com +discord.com +discordapp.com +discord.gg +twitch.tv +EOL + echo "Created default blocked_websites.conf file." +fi # Function to read entries from the configuration file read_entries() { diff --git a/toggle-website-blocking/settings.conf b/toggle-website-blocking/settings.conf index 80bb3d2..f008df1 100644 --- a/toggle-website-blocking/settings.conf +++ b/toggle-website-blocking/settings.conf @@ -1,5 +1,5 @@ HOSTS_FILE="/etc/hosts" -CONFIG_FILE="./blocked_websites.conf" +CONFIG_FILE="blocked_websites.conf" DEFAULT_RESOLVER="127.0.0.1" START_MARKER="# START Blocking Websites by BigBearTechWorld" END_MARKER="# END Blocking Websites by BigBearTechWorld"