Skip to content

Commit

Permalink
Add aliases for systemd alignement #22
Browse files Browse the repository at this point in the history
  • Loading branch information
stablestud committed Nov 25, 2021
1 parent 86bb71b commit 083d041
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion place_files_onto_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ cp "${script_dir_path}/src/share/default/default-sources.list" "${config_dir_pat

echo
echo "Adsorber files have been successfully placed onto the system."
printf "\\033[1;37mTo start (setup the scheduler and backup the hosts file) run 'adsorber setup'\\033[0m\\n"
printf "\\033[1;37mTo begin (setup the scheduler and backup the hosts file) run 'adsorber enable'\\033[0m\\n"

## We don't run Adsorber after installation yet
#adsorber setup --noformatting \
Expand Down
69 changes: 40 additions & 29 deletions src/bin/adsorber
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,33 @@ showHelp()
echo "Usage: adsorber <operation> [<options>|--help]"
echo
echo "(Ad)sorber blocks ads by \"absorbing\" and dumbing them into void."
echo " (with the help of the hosts file)"
echo " (with the help of the hosts file)"
echo
echo "Operation (required):"
echo " setup - setup necessary things needed for Adsorber"
echo " e.g., create backup file of hosts file,"
echo " create scheduler which updates the host file once a week"
# echo " However this should've been done automatically."
echo " update - update hosts file with newest ad-domains"
echo " restore - restore hosts file to its original state"
echo " (it does not remove the scheduler, this should be used temporary)"
echo " revert - reverts the hosts file to the last applied (previous) ad-domains"
echo " disable - completely remove changes made by Adsorber"
echo " e.g., disable scheduler (if set)"
echo " restore hosts file to its original state"
echo " version - show version of this shell script"
echo " help - show this help"
echo "Operations (required):"
echo " - enable, setup"
echo " setup necessary things needed for Adsorber"
echo " e.g., create backup file of hosts file,"
echo " create scheduler which updates the host file once a week"
# echo " However this should've been done automatically."
echo
echo " - start, update"
echo " update hosts file with newest ad-domains"
echo
echo " - stop, restore"
echo " restore hosts file to its original state"
echo " (it does not remove the scheduler, this should be used temporary)"
echo
echo " - revert"
echo " reverts the hosts file to the last applied (previous) ad-domains"
echo
echo " - disable"
echo " completely remove changes made by Adsorber"
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 " - help"
echo " show this help"
echo
echo "Options (optional):"
echo " -y, --yes, --assume-yes - answer all prompts with 'yes'"
Expand All @@ -111,7 +122,7 @@ showHelp()
echo " (e.g 'adsorber update --help)"
echo " --noformatting - turn off coloured and formatted output"
echo
echo "Scheduler options (use with 'setup'):"
echo "Scheduler options (use with 'enable'):"
echo " -ns, --no-scheduler - skip scheduler creation"
echo " -s, --systemd - setup Systemd as scheduler"
echo " -c, --cron - setup Cronjob ..."
Expand All @@ -135,8 +146,8 @@ showHelp()
showSpecificHelp()
{
case "${operation}" in
setup )
printf "\\033[4;37madsorber setup [<options>]\\033[0m:\\n"
setup | enable )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
echo
echo "You should run this command first."
echo " (e.g. after files have been placed onto the system)"
Expand Down Expand Up @@ -166,8 +177,8 @@ showSpecificHelp()
echo
echo "Note: Cron supports only hourly, daily, weekly and monthly."
;;
update )
printf "\\033[4;37madsorber update [<options>]\\033[0m:\\n"
update | start )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
echo
echo "Updates your hosts files with the newest ad-domains fetched from the sources specified in 'sources.list'."
echo
Expand All @@ -180,34 +191,34 @@ showSpecificHelp()
echo " -h, --help - show this help screen"
echo " --noformatting - turn off coloured and formatted output"
;;
restore )
printf "\\033[4;37madsorber restore [<options>]\\033[0m:\\n"
restore | stop )
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
echo
echo "Restore the hosts file to its operating system default, without removing the backup or scheduler."
echo
echo "The command will:"
echo " - Remove lines inserted by Adsorber from `/etc/hosts`"
echo " - Remove lines inserted by Adsorber from '/etc/hosts'"
echo
echo "Note: If you have a scheduler set it'll re-apply ad-domains to your hosts file when triggered."
echo "For this reason this command should be used to temporary disable Adsorber."
echo "(e.g. when it's blocking some sites you need access for a short period of time)"
echo
echo "To re-apply run 'adsorber revert' (for previous host file) or 'adsorber update' (for updated version)."
echo "To re-apply run 'adsorber revert' (for previous host file) or 'adsorber start' (for updated version)."
echo
echo "Possible options:"
echo " -h, --help - show this help screen"
echo " --noformatting - turn off coloured and formatted output"
;;
revert )
printf "\\033[4;37madsorber revert [<options>]\\033[0m:\\n"
printf "\\033[4;37madsorber ${operation} [<options>]\\033[0m:\\n"
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."
echo
echo "The command will:"
echo " - downgrade /etc/hosts with ad-domains applied previously"
echo
echo "To get the latest ad-domains run 'adsorber update'."
echo "To get the latest ad-domains run 'adsorber start'."
echo
echo "Possible options:"
echo " -h, --help - show this help screen"
Expand Down Expand Up @@ -443,7 +454,7 @@ for _option in "${@}"; do
done

case "${operation}" in
setup )
setup | enable )
checkForWrongParameters
checkRoot
config
Expand All @@ -456,13 +467,13 @@ case "${operation}" in
config
disable
;;
update )
update | start )
checkForWrongParameters
checkRoot
config
update
;;
restore )
restore | stop )
checkForWrongParameters
checkRoot
config
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ config_IsVariableSet()
if [ -z "${hosts_file_path}" ] || [ -z "${hosts_file_backup_path}" ] \
|| [ -z "${systemd_dir_path}" ]; then
printf "%bMissing setting(s) in adsorber.conf%b\\n" "${prefix_fatal}" "${prefix_reset}" 1>&2
printf "%bPlease delete adsorber.conf in %s and run 'adsorber setup' to create a new config file.\\n" \
printf "%bPlease delete adsorber.conf in %s and run 'adsorber enable' to create a new config file.\\n" \
"${prefix_warning}" "${config_dir_path}" 1>&2

errorCleanUp
Expand Down
2 changes: 1 addition & 1 deletion src/lib/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ restore()
printf "%bRestoring %s ...%b\\n" "${prefix_title}" "${hosts_file_path}" "${prefix_reset}"
restore_HostsFile
printf "%bSuccessfully purged adsorber section from %s.\\n" "${prefix}" "${hosts_file_path}"
printf "%bTo reapply please run 'adsorber update'.\\n" "${prefix}"
printf "%bTo reapply please run 'adsorber start'.\\n" "${prefix}"
cleanUp
}
4 changes: 2 additions & 2 deletions src/lib/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ update_CheckBackupExist()
# hostname association with 127.0.0.1 and localhost will be lost.
# The user may interactively decide here wheter to proceed or not.
if [ -z "${reply_to_force_prompt}" ]; then
printf "%bBackup of %s does not exist. To backup run 'adsorber setup'.%b\\n" "${prefix_fatal}" "${hosts_file_path}" "${prefix_reset}" 1>&2
printf "%bBackup of %s does not exist. To backup run 'adsorber enable'.%b\\n" "${prefix_fatal}" "${hosts_file_path}" "${prefix_reset}" 1>&2
printf "%bIgnore issue and continue? (May break your hostfile, not recommended) [y/N]: %b" "${prefix_input}" "${prefix_reset}"
read -r reply_to_force_prompt
fi
Expand Down Expand Up @@ -109,7 +109,7 @@ update_ReadSourceList()
if [ ! -s "${config_dir_path}/sources.list" ]; then

if [ ! -s "${config_dir_path}/blacklist" ]; then
printf "%bMissing 'sources.list' and blacklist. To fix run 'adsorber setup'.%b\\n" "${prefix_fatal}" "${prefix_reset}" 1>&2
printf "%bMissing 'sources.list' and blacklist. To fix run 'adsorber enable'.%b\\n" "${prefix_fatal}" "${prefix_reset}" 1>&2
exit 127
fi

Expand Down

0 comments on commit 083d041

Please sign in to comment.