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
|
||||
function uninstall
|
||||
{
|
||||
file_to="$1"
|
||||
file_name="$(basename $1)"
|
||||
path_file_to="$(dirname $1)"
|
||||
local file_to="$1"
|
||||
local file_name="$(basename "$1")"
|
||||
local path_file_to="$(dirname "$1")"
|
||||
|
||||
echo -e $B_BLUE"--- Uninstalling \"$file_name\" ---"$ENDCO
|
||||
|
||||
# -L check if is symlink
|
||||
if [ -f $file_to ] && [ -L $file_to ]
|
||||
if [ -L "$file_to" ]
|
||||
then
|
||||
if grep -q $KEY_PHRASE $file
|
||||
then
|
||||
if [ -f $file_to.hubak0 ]
|
||||
then
|
||||
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
|
||||
restore_bak $file_to
|
||||
fi
|
||||
echo -e $YELLOW"Found symlink: $file_to"$ENDCO
|
||||
# The symlink target is what we need to check for the key phrase
|
||||
local target_file=$(readlink "$file_to")
|
||||
if [ ! -f "$target_file" ]; then
|
||||
echo -e $RED"Symlink is broken."$ENDCO
|
||||
# Decide if you want to do something with broken symlinks, e.g. remove them.
|
||||
return
|
||||
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
|
||||
echo # Add a blank line for readability
|
||||
}
|
||||
|
||||
|
||||
# argument : directory where the config file should go
|
||||
echo -e $B_MAGENTA"--- Starting uninstall process ---"$ENDCO"\n"
|
||||
uninstall "$HOME/.screenrc"
|
||||
uninstall "$HOME/.vimrc"
|
||||
uninstall "$HOME/.zshrc"
|
||||
uninstall "$home/.vim/templates/skeleton_color.h"
|
||||
uninstall "$home/.vim/templates/skeleton.cpp"
|
||||
uninstall "$home/.vim/templates/skeleton.hpp"
|
||||
uninstall "$home/.vim/templates/skeleton_main.cpp"
|
||||
uninstall "$home/.vim/templates/skeleton_makefile"
|
||||
uninstall "$HOME/.vim/templates/skeleton_colors.h"
|
||||
uninstall "$HOME/.vim/templates/skeleton.cpp"
|
||||
uninstall "$HOME/.vim/templates/skeleton.hpp"
|
||||
uninstall "$HOME/.vim/templates/skeleton_main.cpp"
|
||||
uninstall "$HOME/.vim/templates/skeleton_makefile"
|
||||
|
||||
Reference in New Issue
Block a user