85 lines
2.2 KiB
Bash
85 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
# COLORS
|
|
source ./asides/color.sh
|
|
|
|
KEY_PHRASE="#hugogogo#"
|
|
|
|
# receive 1 argument : absolute path to config file
|
|
function restore_bak
|
|
{
|
|
file_to="$1"
|
|
file_name="$(basename $1)"
|
|
path_file_to="$(dirname $1)"
|
|
number=0
|
|
while [ -f $file_to.hubak$number ]
|
|
do
|
|
((number+=1))
|
|
done
|
|
((number-=1))
|
|
echo -en $YELLOW"in "
|
|
echo -en $CYAN"\"$path_file_to/\""
|
|
echo -en $YELLOW", mv "
|
|
echo -en $CYAN"\"$file_name.hubak$number\""
|
|
echo -en $YELLOW" to "
|
|
echo -en $CYAN"\"$file_name\""$ENDCO"\n"
|
|
mv $file_to.hubak$number $file_to
|
|
}
|
|
|
|
# receive 1 argument : absolute path to config file
|
|
function uninstall
|
|
{
|
|
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 [ -L "$file_to" ]
|
|
then
|
|
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_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"
|