improve uninstall script
This commit is contained in:
62
uninstall.sh
62
uninstall.sh
@@ -29,34 +29,56 @@ function restore_bak
|
|||||||
# receive 1 argument : absolute path to config file
|
# receive 1 argument : absolute path to config file
|
||||||
function uninstall
|
function uninstall
|
||||||
{
|
{
|
||||||
file_to="$1"
|
local file_to="$1"
|
||||||
file_name="$(basename $1)"
|
local file_name="$(basename "$1")"
|
||||||
path_file_to="$(dirname $1)"
|
local path_file_to="$(dirname "$1")"
|
||||||
|
|
||||||
|
echo -e $B_BLUE"--- Uninstalling \"$file_name\" ---"$ENDCO
|
||||||
|
|
||||||
# -L check if is symlink
|
# -L check if is symlink
|
||||||
if [ -f $file_to ] && [ -L $file_to ]
|
if [ -L "$file_to" ]
|
||||||
then
|
then
|
||||||
if grep -q $KEY_PHRASE $file
|
echo -e $YELLOW"Found symlink: $file_to"$ENDCO
|
||||||
then
|
# The symlink target is what we need to check for the key phrase
|
||||||
if [ -f $file_to.hubak0 ]
|
local target_file=$(readlink "$file_to")
|
||||||
then
|
if [ ! -f "$target_file" ]; then
|
||||||
echo -en $YELLOW"in "
|
echo -e $RED"Symlink is broken."$ENDCO
|
||||||
echo -en $CYAN"\"$path_file_to/\""
|
# Decide if you want to do something with broken symlinks, e.g. remove them.
|
||||||
echo -en $YELLOW", rm symlink "
|
return
|
||||||
echo -en $CYAN"\"$file_name\""$ENDCO"\n"
|
|
||||||
rm $file_to
|
|
||||||
restore_bak $file_to
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if grep -q "$KEY_PHRASE" "$target_file"
|
||||||
|
then
|
||||||
|
echo -e $GREEN"Key phrase found. This is one of our config files."$ENDCO
|
||||||
|
echo -en $YELLOW"in "
|
||||||
|
echo -en $CYAN"\"$path_file_to/\""
|
||||||
|
echo -en $YELLOW", rm symlink "
|
||||||
|
echo -en $CYAN"\"$file_name\""$ENDCO"\n"
|
||||||
|
rm "$file_to"
|
||||||
|
|
||||||
|
if [ -f "$file_to.hubak0" ]
|
||||||
|
then
|
||||||
|
restore_bak "$file_to"
|
||||||
|
else
|
||||||
|
echo -e $YELLOW"No backup file found to restore."$ENDCO
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e $RED"Key phrase not found. Skipping to avoid removing a file not managed by this script."$ENDCO
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e $YELLOW"Not a symlink, or does not exist. Skipping: $file_to"$ENDCO
|
||||||
fi
|
fi
|
||||||
|
echo # Add a blank line for readability
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# argument : directory where the config file should go
|
# argument : directory where the config file should go
|
||||||
|
echo -e $B_MAGENTA"--- Starting uninstall process ---"$ENDCO"\n"
|
||||||
uninstall "$HOME/.screenrc"
|
uninstall "$HOME/.screenrc"
|
||||||
uninstall "$HOME/.vimrc"
|
uninstall "$HOME/.vimrc"
|
||||||
uninstall "$HOME/.zshrc"
|
uninstall "$HOME/.zshrc"
|
||||||
uninstall "$home/.vim/templates/skeleton_color.h"
|
uninstall "$HOME/.vim/templates/skeleton_colors.h"
|
||||||
uninstall "$home/.vim/templates/skeleton.cpp"
|
uninstall "$HOME/.vim/templates/skeleton.cpp"
|
||||||
uninstall "$home/.vim/templates/skeleton.hpp"
|
uninstall "$HOME/.vim/templates/skeleton.hpp"
|
||||||
uninstall "$home/.vim/templates/skeleton_main.cpp"
|
uninstall "$HOME/.vim/templates/skeleton_main.cpp"
|
||||||
uninstall "$home/.vim/templates/skeleton_makefile"
|
uninstall "$HOME/.vim/templates/skeleton_makefile"
|
||||||
|
|||||||
Reference in New Issue
Block a user