Skip to content

Commit

Permalink
Remove hashed command after removal
Browse files Browse the repository at this point in the history
  • Loading branch information
stablestud committed Apr 21, 2018
1 parent 4bf9c68 commit 84969bc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 30 deletions.
18 changes: 9 additions & 9 deletions portable_adsorber.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ readonly source_dir_path="$(cd "$(dirname "${0}")" && pwd)"
echo ""

# Call adsorber from the src/bin/ directory
if ("${source_dir_path}/src/bin/adsorber" ${parameters}); then
exit_code=$?

runAdsorber()
{
( "${source_dir_path}/src/bin/adsorber" ${parameters} )
_exit_code="${?}"
echo ""
echo "Adsorber in portable-mode exited with code ${exit_code}."
}
if runAdsorber; then
echo "Adsorber in portable-mode exited with code ${_exit_code}."
else
exit_code=$?

echo ""
# I defined exit code 80 as an error code if wrong or no input has been made
if [ "${exit_code}" -eq 80 ]; then
if [ "${_exit_code}" -eq 80 ]; then
echo "You've supplied no or wrong parameters."
fi

echo "Adsorber in portable-mode exited with code ${exit_code}. Thats an error."
echo "Adsorber in portable-mode exited with code ${_exit_code}. Thats an error."
fi
24 changes: 19 additions & 5 deletions remove_from_system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ fi

echo ""

echo "Running 'adsorber remove -y' ..."
(adsorber remove -y) \
|| {
echo ""
printf "\033[0;93mSomething went wrong at running Adsorber's own removal action. Doing it the hard way...\\n\033[0m"
echo "Maybe Adsorber has been already removed?"
printf "\\033[0;93mSomething went wrong at running Adsorber's own removal action.\\nDoing it the hard way ...\\n\\033[0m"
echo "Maybe Adsorber has been removed already?"

# Doing it the hard way .., removing everything manually
rm "${systemd_timer_path}" 2>/dev/null && echo "Removed ${systemd_timer_path}"
Expand All @@ -93,9 +94,22 @@ echo ""

# Remove placed files from the specified locations
rm -r "${executable_path}" 2>/dev/null && echo "Removed ${executable_path}"
rm -r "${library_dir_path}" 2>/dev/null && echo "Removed ${library_dir_path}"
rm -r "${shareable_dir_path}" 2>/dev/null && echo "Removed ${shareable_dir_path}"
rm -r "${config_dir_path}" 2>/dev/null && echo "Removed ${config_dir_path}"
rm -r "${library_dir_path}" 2>/dev/null && echo "Cleaned ${library_dir_path}"
rm -r "${shareable_dir_path}" 2>/dev/null && echo "Cleaned ${shareable_dir_path}"
rm -r "${config_dir_path}" 2>/dev/null && echo "Cleaned ${config_dir_path}"

echo "Clearing shell cache ..."
# Remove the adsorber command from cache/hashtable
if command -v hash 1>/dev/null; then
# Works in bash
hash -d adsorber 2>/dev/null
elif command -v rehash 1>/dev/null; then
# For csh and zsh shells
rehash
else
# Should work in all shells
export PATH="${PATH}"
fi

echo ""

Expand Down
13 changes: 6 additions & 7 deletions src/bin/adsorber
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
readonly tmp_dir_path="/tmp/adsorber"
readonly debug="false"


############[ DO NOT EDIT ]#####################################################
# NOTE: following values will be changed when installed with
# 'install-to-system.sh', if you want to change them, change them there
Expand All @@ -36,7 +35,7 @@ checkRoot()
{
# Changing the hosts file requires root rights!
if [ "$(id -g)" -ne 0 ]; then
echo "$(id -un), I require way more more power then this! How about.. root ..? ;)" 1>&2
echo "$(id -un), I require way more more power then this! How about .. root ..? ;)" 1>&2
exit 126
fi

Expand Down Expand Up @@ -117,7 +116,7 @@ showSpecificHelp()
{
case "${operation}" in
install )
printf "%badsorber install [<options>]%b:\\n" "${uwhite}" "${prefix_reset}"
printf "%badsorber install [<options>]%b:\\n" "${prefix_underline}" "${prefix_reset}"
echo
echo "You should run this command first."
echo
Expand All @@ -136,7 +135,7 @@ showSpecificHelp()
echo " -h, --help - show this help screen"
;;
update )
printf "%badsorber update [<options>]%b:\\n" "${uwhite}" "${prefix_reset}"
printf "%badsorber update [<options>]%b:\\n" "${prefix_underline}" "${prefix_reset}"
echo
echo "To keep the hosts file up-to-date."
echo
Expand All @@ -149,7 +148,7 @@ showSpecificHelp()
echo " -h, --help - show this help screen"
;;
restore )
printf "%badsorber restore [<options>]%b:\\n" "${uwhite}" "${prefix_reset}"
printf "%badsorber restore [<options>]%b:\\n" "${prefix_underline}" "${prefix_reset}"
echo
echo "To restore the hosts file temporary, without removing the backup."
echo
Expand All @@ -167,7 +166,7 @@ showSpecificHelp()
echo " -h, --help - show this help screen"
;;
revert )
printf "%badsorber revert [<options>]%b:\\n" "${uwhite}" "${prefix_reset}"
printf "%badsorber revert [<options>]%b:\\n" "${prefix_underline}" "${prefix_reset}"
echo
echo "To revert to the last hosts file, good use if the"
echo "current host file was corrupted."
Expand All @@ -181,7 +180,7 @@ showSpecificHelp()
echo " -h, --help - show this help screen"
;;
remove )
printf "%badsorber remove [<options>]%b:\\n" "${uwhite}" "${prefix_reset}"
printf "%badsorber remove [<options>]%b:\\n" "${prefix_underline}" "${prefix_reset}"
echo
echo "To completely remove changes made by Adsorber."
echo
Expand Down
11 changes: 6 additions & 5 deletions src/lib/colours.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
# (Note the underscore in the beginning of _extra_under_score!)

readonly prefix=" "
readonly prefix_fatal="\033[0;91mE " # 'E' in intensity red
readonly prefix_info="\033[0;97m " # Intensity white
readonly prefix_fatal="\\033[0;91mE " # 'E' in intensity red
readonly prefix_info="\\033[0;97m " # Intensity white
readonly prefix_input="> "
readonly prefix_title="\033[1;37m" # Bold white
readonly prefix_title="\\033[1;37m" # Bold white
readonly prefix_warning="- "
readonly prefix_reset='\033[0m' # Default colour
readonly prefix_reset="\\033[0m" # Default colour
readonly prefix_underline="\\033[4;37m" # White Underline

# Regular Colors
#readonly BLACK='\033[0;30m' # Black
Expand Down Expand Up @@ -45,7 +46,7 @@ readonly prefix_reset='\033[0m' # Default colour
#readonly UBLUE='\033[4;34m' # Blue
#readonly UPURPLE='\033[4;35m' # Purple
#readonly UCYAN='\033[4;36m' # Cyan
readonly uwhite='\033[4;37m' # White
#readonly uwhite='\033[4;37m' # White

# Background
#readonly BG_BLACK='\033[40m' # Black
Expand Down
4 changes: 2 additions & 2 deletions src/lib/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ config_ReadConfig()
;;
http_proxy=* )
if [ -z "${http_proxy}" ]; then
export "${_line}"
export "${_line?}"
else
echo "${prefix_warning}'http_proxy' already defined, using: ${http_proxy}"
fi
;;
https_proxy=* )
if [ -z "${https_proxy}" ]; then
export "${_line}"
export "${_line?}"
else
echo "${prefix_warning}'https_proxy' already defined, using: ${https_proxy}"
fi
Expand Down
2 changes: 1 addition & 1 deletion src/lib/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ update_FetchSources()
if wget "${_domain}" --show-progress -L --timeout=30 -t 1 -nv -O - >> "${tmp_dir_path}/fetched"; then
_successful_count=$((_successful_count+1))
else
printf "%bwget couldn't fetch: %s\\n" "${_domain}" 1>&2
printf "%bwget couldn't fetch: %s\\n" "${prefix_warning}" "${_domain}" 1>&2
fi
# Is curl installed? If yes download the hosts files.
elif command -v curl 2>/dev/null 1>&2; then
Expand Down
2 changes: 1 addition & 1 deletion test/shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi

echo "Running shellcheck ..."

shellcheck -e SC2154 -e SC1090 -e SC2163 \
shellcheck -e SC1090,SC2086,SC2154,SC2163 \
"${source_dir_path}/../src/bin/adsorber" \
"${source_dir_path}/../src/lib/config.sh" \
"${source_dir_path}/../src/lib/install.sh" \
Expand Down

0 comments on commit 84969bc

Please sign in to comment.