Skip to content

Commit

Permalink
Add ADSORBER_DEBUG environment variable for debug purposes
Browse files Browse the repository at this point in the history
This commit makes Adsorber print out debugging information when the
environment variable ADSORBER_DEBUG is set.
This is useful to view Adsorbers procedures to aid in finding issues
  • Loading branch information
stablestud committed Jul 17, 2024
1 parent 873300f commit 1eb651a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ Config files are located at: /usr/local/etc/adsorber/
Documentation: https://github.com/stablestud/adsorber/blob/master/README.md
If you encounter any issues please report them to the Github repository.
If you create an issue please provide the debug output from Adsorber,
it can be generated with the environment variable ADSORBER_DEBUG=true
```

### Operations (required):
Expand Down
2 changes: 0 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ printHelp()
echo " Will place Adsorbers executables and other"
echo " files relevant to Adsorber into the system."
echo
printf "\\033[4;37mNote\\033[0m: Adsorbers own 'setup' command will not do the same action as this script.\\n"
echo
echo "Usage: ${0} [option]:"
echo
echo "Options:"
Expand Down
23 changes: 15 additions & 8 deletions src/bin/adsorber
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@

readonly tmp_dir_path="/tmp/adsorber"
readonly cache_dir_path="/var/cache/adsorber"
readonly debug="false"



############[ DO NOT EDIT ]#####################################################

if [ -z "${ADSORBER_DEBUG+no}" ]; then
readonly debug="false"
else
readonly debug="true"
set -x
fi

# NOTE: following values will be changed when installed with
# 'install.sh', if you want to change them, change them there

Expand Down Expand Up @@ -106,7 +111,7 @@ showHelp()
echo " e.g., disable scheduler (if set)"
echo " restore hosts file to its original state"
echo " - version"
echo " show version of this shell script"
echo " show version of Adsorber"
echo " - help"
echo " show this help"
echo
Expand Down Expand Up @@ -134,6 +139,8 @@ showHelp()
echo
echo "Documentation: https://github.com/stablestud/adsorber/blob/master/README.md"
echo "If you encounter any issues please report them to the Github repository."
echo "If you create an issue please provide the debug output from Adsorber,"
echo "it can be generated with the environment variable ADSORBER_DEBUG=true"

exit 0
}
Expand All @@ -143,7 +150,7 @@ showSpecificHelp()
{
case "${operation}" in
setup | enable )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
printf "\\033[4;37madsorber %s [<options>]\\033[0m:\\n" "${operation}"
echo
echo "You should run this command first."
echo " (e.g. after files have been placed onto the system)"
Expand Down Expand Up @@ -174,7 +181,7 @@ showSpecificHelp()
echo "Note: Cron supports only hourly, daily, weekly and monthly."
;;
update | start )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
printf "\\033[4;37madsorber %s [<options>]\\033[0m:\\n" "${operation}"
echo
echo "Updates your hosts files with the newest ad-domains fetched from the sources specified in 'sources.list'."
echo
Expand All @@ -188,7 +195,7 @@ showSpecificHelp()
echo " --noformatting - turn off coloured and formatted output"
;;
restore | stop )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
printf "\\033[4;37madsorber %s [<options>]\\033[0m:\\n" "${operation}"
echo
echo "Restore the hosts file to its operating system default, without removing the backup or scheduler."
echo
Expand All @@ -206,7 +213,7 @@ showSpecificHelp()
echo " --noformatting - turn off coloured and formatted output"
;;
revert )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
printf "\\033[4;37madsorber %s [<options>]\\033[0m:\\n" "${operation}"
echo
echo "Revert the current hosts file to the previously applied ad-domains"
echo "Use it if the current host file has been corrupted or misses previously applied ad-domains."
Expand All @@ -221,7 +228,7 @@ showSpecificHelp()
echo " --noformatting - turn off coloured and formatted output"
;;
disable )
printf "\\033[4;37madsorber disable [<options>]\\033[0m:\\n"
printf "\\033[4;37madsorber %s [<options>]\\033[0m:\\n" "${operation}"
echo
echo "Completely disable all background tasks (schedulers) and remove all changes made by Adsorber."
echo
Expand Down
1 change: 1 addition & 0 deletions src/lib/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ config_PrintVariables()
config()
{
printf "%bReading configuration ...%b\\n" "${prefix_title}" "${prefix_reset}"
[ "${debug}" = "true" ] && config_PrintVariables
config_CreateTmpDir
config_CopySourceList
config_CopyWhiteList
Expand Down

0 comments on commit 1eb651a

Please sign in to comment.