adding uninstall functions

This commit is contained in:
Dict Xiong 2022-05-15 12:55:50 +08:00 committed by GitHub
parent 7a7526d184
commit c7f3a19091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 10 deletions

View File

@ -64,11 +64,10 @@ antigen apply
export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd ) export DOTFILES=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
dfs() dfs()
{ {
if [[ $1 == update ]]; then case $1 in
(cd "$DOTFILES" && env git pull) update ) (cd "$DOTFILES" && env git pull) ;;
else * ) echo "unknown command \"$1\". available: update" ;;
echo "unknown command \"$1\". available: update" esac
fi
} }
# alias # alias

View File

@ -121,6 +121,16 @@ insert_if_not_exist()
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename" grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
} }
delete_if_exist()
{
filename=$1
line=$2
fmt_note "removing \"$line\" from \"$filename\" ..."
if [ -f "$filename" ]; then
grep -vxF -- "$line" "$filename" >> "$filename"
fi
}
create_symlink() create_symlink()
{ {
src=$1 src=$1
@ -146,22 +156,47 @@ create_symlink()
ln -s $src $dest ln -s $src $dest
} }
delete_link_if_match()
{
src=$1
dest=$2
if [ "$(readlink $dest)" -ef "$src" ]; then
fmt_note "removing symlink \"$dest\" ..."
echo ----------
env stat $dest
echo ----------
rm $dest
fi
}
install_crontab(){ install_crontab(){
fmt_note "installing \"$crontab_job\" to crontab ..." fmt_note "installing \"$crontab_job\" to crontab ..."
( crontab -l | grep -v "${crontab_job//\*/\\\*}" | grep -v "no crontab for"; echo "$crontab_job" ) | crontab - ( crontab -l | grep -vxF "${crontab_job}" | grep -v "no crontab for"; echo "$crontab_job" ) | crontab -
} }
uninstall_crontab(){ uninstall_crontab(){
fmt_note uninstalling "\"$crontab_job\"" from crontab ... fmt_note "removing \"$crontab_job\" from crontab ..."
( crontab -l | grep -v"$crontab_job" ) | crontab - ( crontab -l | grep -vxF "$crontab_job" ) | crontab -
} }
install(){ install(){
install_crontab install_crontab
insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2" insert_if_not_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2" create_symlink "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
fmt_note "job done!" fmt_note "done installing!"
}
uninstall(){
uninstall_crontab
delete_if_exist "${HOME}/.zshrc" "source ${dotfile_home_path}/.zshrc2"
delete_link_if_match "${dotfile_path}/.ssh/authorized_keys2" "${HOME}/.ssh/authorized_keys2"
fmt_note "done uninstalling!"
} }
setup_color setup_color
install case $1 in
^$|-i ) install ;;
-r ) uninstall ;;
* ) echo "unknown command \"$1\". available: -i, -r" ;;
esac