Skip to content

Commit

Permalink
Merge pull request #15 from stablestud/dev
Browse files Browse the repository at this point in the history
Make Adsorber update the hosts file inline
  • Loading branch information
stablestud committed Nov 1, 2020
2 parents 0683be2 + 0b4b58f commit 666a2d9
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 477 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Adsorber
[![Latest version](https://img.shields.io/badge/latest-v0.5.2-brightgreen.svg)](https://github.com/stablestud/adsorber/releases)
[![Latest version](https://img.shields.io/badge/latest-v1.0.0-brightgreen.svg)](https://github.com/stablestud/adsorber/releases)
[![License](https://img.shields.io/github/license/stablestud/adsorber.svg)](https://github.com/stablestud/adsorber/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/stablestud/adsorber.svg)](https://github.com/stablestud/adsorber/stargazers)

Expand Down Expand Up @@ -84,11 +84,12 @@ The script also works on [portable mode](#portable-mode) setups. However running

#### Manual removal
If you prefer manual removal, here you go:
1. copy:
* `/etc/hosts.original` to `/etc/hosts`, overwriting it
1. delete inline:
* `/etc/hosts`
Delete everything between the lines:
`# BEGIN OF ADSORBER SECTION` and `# END OF ADSORBER SECTION`
2. remove:
* `/etc/hosts.original`
* `/etc/hosts.previous`
* `/usr/local/bin/adsorber`
* `/usr/local/etc/adsorber/`
* `/usr/local/lib/adsorber/`
Expand All @@ -99,7 +100,8 @@ If you prefer manual removal, here you go:
* `/etc/cron.daily/80adsorber`
* `/etc/cron.weekly/80adsorber`
* `/etc/cron.monthly/80adsorber`
* **`/var/log/adsorber.log`**
* `/var/cache/adsorber`
* **`/var/log/adsorber.log`** <- won't be removed automatically
* `/tmp/adsorber/`

Not all files of the above will exist, so dont worry if they are not found.
Expand Down Expand Up @@ -207,9 +209,9 @@ Possible options are:
Reverts the last applied hosts-file by Adsorber.

The command will:
* copy `/etc/hosts.previous` to `/etc/hosts`, overwriting the newest `/etc/hosts`.
* downgrade `/etc/hosts` with ad-domains applied previously

This is useful if the newest hosts file contains less or no ad-domains, because a source
This is useful if the newest hosts file contains less or no ad-domains, because a source
was unreachable and you don't want to loose the ad-servers supplied previously from this source.

Possible option:
Expand Down Expand Up @@ -238,7 +240,7 @@ To completely uninstall see [removal](#removal).
The command will:
* disable all schedulers (systemd, cronjob)
* restore the hosts file to it's original state
* remove all leftovers (previous hosts file, etc)
* remove all leftovers (cache, etc)

Possible options are:
* [`-y`, `--yes`, `--assume-yes`](#-y---yes---assume-yes)
Expand Down
75 changes: 38 additions & 37 deletions remove_files_from_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ readonly hosts_file_backup_path="/etc/hosts.original"
readonly hosts_file_previous_path="/etc/hosts.previous"
readonly systemd_dir_path="/etc/systemd/system"
readonly tmp_dir_path="/tmp/adsorber"
readonly log_file_path="/var/log/adsorber.log" # Log file won't be removed
readonly cache_dir_path="/var/cache/adsorber"
readonly log_file_path="/var/log/adsorber.log" # Log file won't be removed

##########[ End of configuration ]##############################################

Expand All @@ -40,7 +41,7 @@ readonly script_dir_path="$(cd "$(dirname "${0}")" && pwd)"

printLocation()
{
echo "Going to remove files from:"
echo "Going to remove files from:"
echo " - main exectuable: ${executable_path}"
echo " - other executables: ${library_dir_path}"
echo " - configuration: ${config_dir_path}"
Expand All @@ -66,20 +67,20 @@ printHelp()
echo
printLocation

exit 0
exit 0
}


prompt="${1}"

if [ "${prompt}" = "help" ] || [ "${prompt}" = "h" ] || [ "${prompt}" = "-h" ] || [ "${prompt}" = "--help" ]; then
printHelp
printHelp
fi


# Prompt user if sure about to remove Adsorber from the system
if [ -z "${prompt}" ]; then
printf "Are you sure you want to remove Adsorber from the system? [(y)es/(N)o]: "
printf "Are you sure you want to remove Adsorber from the system? [(y)es/(N)o]: "
read -r prompt
fi

Expand All @@ -103,59 +104,59 @@ fi

# Run Adsorber's own removal, if it fails do it manually
if command -v adsorber 1>/dev/null; then
printf "\\nRunning 'adsorber disable -y --noformatting' ...\\n\\n"
( adsorber "disable" "-y" "--noformatting" ) \
|| {
echo
printf "\\033[0;93mSomething went wrong at running Adsorber's own disable operation.\\nNo worries, I can handle it ...\\n\\033[0m"
echo "Maybe Adsorber has been already removed ?"
readonly _hard_way="true"
}
printf "\\nRunning 'adsorber disable -y --noformatting' ...\\n\\n"
( adsorber "disable" "-y" "--noformatting" ) \
|| {
echo
printf "\\033[0;93mSomething went wrong at running Adsorber's own disable operation.\\nNo worries, I can handle it ...\\n\\033[0m"
echo "Maybe Adsorber has been already removed ?"
readonly _hard_way="true"
}
else
readonly _hard_way="true"
readonly _hard_way="true"
fi


# Doing it the hard way .., removing everything manually
if [ "${_hard_way}" = "true" ]; then
printf "\\nTrying portable_adsorber.sh ... "

if "${script_dir_path}/portable_adsorber.sh" "disable" "-y" "--noformatting" 2>/dev/null 1>&2; then
printf "found\\n"
printf "Removed Adsorber successfully\\n"
else
printf "no luck\\n"
"${script_dir_path}/misc/clean.sh" 2>/dev/null 1>&2
fi

printf "\\nTrying portable_adsorber.sh ... "

if "${script_dir_path}/portable_adsorber.sh" "disable" "-y" "--noformatting" 2>/dev/null 1>&2; then
printf "found\\n"
printf "Removed Adsorber successfully\\n"
else
printf "no luck\\n"
"${script_dir_path}/misc/clean.sh" 2>/dev/null 1>&2
fi

rm "${systemd_dir_path}/adsorber.timer" 2>/dev/null && echo "Removed ${systemd_dir_path}/adsorber.timer"
rm "${systemd_dir_path}/adsorber.service" 2>/dev/null && echo "Removed ${systemd_dir_path}/adsorber.service"
systemctl daemon-reload 2>/dev/null && echo "Reloaded systemctl daemon"

# Remove all crontabs
# Remove all crontabs
if [ -f "/etc/cron.hourly/80adsorber" ]; then
rm "/etc/cron.hourly/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.hourly/"
fi
rm "/etc/cron.hourly/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.hourly/"
fi

if [ -f "/etc/cron.daily/80adsorber" ]; then
rm "/etc/cron.daily/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.daily/"
fi
rm "/etc/cron.daily/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.daily/"
fi

if [ -f "/etc/cron.weekly/80adsorber" ]; then
rm "/etc/cron.weekly/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.weekly/"
fi
rm "/etc/cron.weekly/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.weekly/"
fi

if [ -f "/etc/cron.monthly/80adsorber" ]; then
rm "/etc/cron.monthly/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.monthly/"
fi
rm "/etc/cron.monthly/80adsorber" 2>/dev/null \
&& echo "Removed cronjob from /etc/cron.monthly/"
fi


rm -r "${tmp_dir_path}" 2>/dev/null && echo "Removed ${tmp_dir_path}"
rm -r "${cache_dir_path}" 2>/dev/null && echo "Removed ${cache_dir_path}"

if [ -f "${hosts_file_backup_path}" ]; then
echo "Backup of hosts file found at ${hosts_file_backup_path}"
Expand Down

0 comments on commit 666a2d9

Please sign in to comment.