需求:一键卸载程序及相关目录删除,可选卸载或保留程序
#!/usr/bin/env bash
##uninstall
##stop bcchain
function StopBcchain(){
if $(systemctl -q is-active bcchain.service) ; then
systemctl stop bcchain.service
fi
uid=$(id -u bcchain 2>/dev/null)
if [[ "${uid:-}" != "0" ]];then
pid=$(ps -fubcchain 2>/dev/null|grep 'bcchain'|awk '$0 !~/grep/ {print $2}'|sed -e 's/\n/ /')
if [[ "${pid:-}" != "" ]]; then
echo "kill old process. ${pid}"
kill -9 ${pid}
fi
fi
}
###
echo ""
echo "Do you want to uninstall & remove all of this bcb node?"
options=("yes" "no")
select opt in "${options[@]}" ; do
case ${opt} in
"yes")
echo ""
echo "Yes, uninstall & remove all of this bcb node"
StopBcchain
systemctl disable bcchain.service
rm -fr /etc/bcchain
rm -fr /home/bcchain
echo "The deleted directories are /etc/bcchain,/home/bcchain."
echo ""
break
;;
"no")
echo ""
echo "No, keep the old bcb node"
echo ""
exit 1
break
;;
*) echo "Invalid choice.";;
esac
done