feat: enhance removal script with command-line options for data retention

This commit is contained in:
chenhaoran 2025-03-18 15:15:58 +08:00
parent 3bc6635de3
commit e8cc3fcc9c
1 changed files with 47 additions and 15 deletions

View File

@ -236,6 +236,39 @@ function remove_data_and_config() {
[ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir}
}
# 解析命令行参数
interactive_remove="yes"
while getopts "e:h" opt; do
case $opt in
e)
if [ "$OPTARG" == "yes" ]; then
interactive_remove="no"
remove_flag=false
echo "It will remove only the binary files and keep all the data, log, and configuration files."
elif [ "$OPTARG" == "no" ]; then
interactive_remove="no"
remove_flag=true
echo "It will remove the binary files and all the data, log, and configuration files."
else
echo "Invalid option for -e: $OPTARG"
exit 1
fi
;;
h)
echo "Usage: $(basename $0) -e [yes | no] "
echo " select 'yes' to skip prompt and remove only the binary files and keep all the data, log, and configuration files."
echo " select 'no' to skip prompt and remove the binary files and all the data, log, and configuration files"
exit 0
;;
*)
echo "Invalid option: -$opt"
exit 1
;;
esac
done
if [ "$interactive_remove" == "yes" ]; then
echo
echo "Do you want to remove all the data, log and configuration files? [y/n]"
read answer
@ -251,6 +284,7 @@ if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then
fi
fi
echo
fi
if [ -e ${install_main_dir}/uninstall_${PREFIX}x.sh ]; then
if [ X$remove_flag == X"true" ]; then
@ -260,7 +294,6 @@ if [ -e ${install_main_dir}/uninstall_${PREFIX}x.sh ]; then
fi
fi
if [ "$osType" = "Darwin" ]; then
clean_service_on_launchctl
${csudo}rm -rf /Applications/TDengine.app
@ -299,7 +332,6 @@ elif echo $osinfo | grep -qwi "centos"; then
${csudo}rpm -e --noscripts tdengine >/dev/null 2>&1 || :
fi
command -v systemctl >/dev/null 2>&1 && ${csudo}systemctl daemon-reload >/dev/null 2>&1 || true
echo
echo "${productName} is removed successfully!"