From e8cc3fcc9c5c3d05ccc92d9f33178787fffad657 Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Tue, 18 Mar 2025 15:15:58 +0800 Subject: [PATCH 1/3] feat: enhance removal script with command-line options for data retention --- packaging/tools/remove.sh | 62 +++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 621ed7f2a9..7aafaa0cb3 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -236,21 +236,55 @@ function remove_data_and_config() { [ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir} } -echo -echo "Do you want to remove all the data, log and configuration files? [y/n]" -read answer -remove_flag=false -if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then - confirmMsg="I confirm that I would like to delete all data, log and configuration files" - echo "Please enter '${confirmMsg}' to continue" +# 解析命令行参数 +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 - if [ X"$answer" == X"${confirmMsg}" ]; then - remove_flag=true - else - echo "answer doesn't match, skip this step" + remove_flag=false + if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then + confirmMsg="I confirm that I would like to delete all data, log and configuration files" + echo "Please enter '${confirmMsg}' to continue" + read answer + if [ X"$answer" == X"${confirmMsg}" ]; then + remove_flag=true + else + echo "answer doesn't match, skip this step" + fi fi + echo fi -echo 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,8 +332,7 @@ 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!" -echo +echo \ No newline at end of file From e7e65a059de3071d1dc91e72fe57c1d50df3e61d Mon Sep 17 00:00:00 2001 From: WANG Xu Date: Tue, 18 Mar 2025 16:23:20 +0800 Subject: [PATCH 2/3] refactor: silent mode Signed-off-by: WANG Xu --- packaging/tools/remove.sh | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index 7aafaa0cb3..bf5252e448 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -236,49 +236,50 @@ function remove_data_and_config() { [ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir} } -# 解析命令行参数 +function usage() { + echo -e "\nUsage: $(basename $0) [-e ]" + echo "-e: silent mode, specify whether to remove all the data, log and configuration files." + echo " yes: remove the data, log, and configuration files." + echo " no: don't remove the data, log, and configuration files." +} + +# main interactive_remove="yes" +remove_flag="false" + while getopts "e:h" opt; do case $opt in e) + interactive_remove="no" + 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." + remove_flag="true" + echo "Remove 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." + remove_flag="false" + echo "Do NOT remove the data, log, and configuration files." else echo "Invalid option for -e: $OPTARG" + usage 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" + h | *) + usage 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]" + echo -e "\nDo you want to remove all the data, log and configuration files? [y/n]" read answer - remove_flag=false if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then confirmMsg="I confirm that I would like to delete all data, log and configuration files" echo "Please enter '${confirmMsg}' to continue" read answer if [ X"$answer" == X"${confirmMsg}" ]; then - remove_flag=true + remove_flag="true" else echo "answer doesn't match, skip this step" fi From f830d09e7f6dcb434f6597f6681a274dbf5f4e7d Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Tue, 18 Mar 2025 17:12:12 +0800 Subject: [PATCH 3/3] fix: update removal scripts to check for symbolic links before deletion --- packaging/tools/remove.sh | 6 +++--- packaging/tools/remove_client.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packaging/tools/remove.sh b/packaging/tools/remove.sh index bf5252e448..ec73ca88cf 100755 --- a/packaging/tools/remove.sh +++ b/packaging/tools/remove.sh @@ -162,9 +162,9 @@ remove_service_of() { remove_tools_of() { _tool=$1 kill_service_of ${_tool} - [ -e "${bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${bin_link_dir}/${_tool} || : + [ -L "${bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${bin_link_dir}/${_tool} || : [ -e "${installDir}/bin/${_tool}" ] && ${csudo}rm -rf ${installDir}/bin/${_tool} || : - [ -e "${local_bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${local_bin_link_dir}/${_tool} || : + [ -L "${local_bin_link_dir}/${_tool}" ] && ${csudo}rm -rf ${local_bin_link_dir}/${_tool} || : } remove_bin() { @@ -257,7 +257,7 @@ while getopts "e:h" opt; do echo "Remove all the data, log, and configuration files." elif [ "$OPTARG" == "no" ]; then remove_flag="false" - echo "Do NOT remove the data, log, and configuration files." + echo "Do not remove the data, log, and configuration files." else echo "Invalid option for -e: $OPTARG" usage diff --git a/packaging/tools/remove_client.sh b/packaging/tools/remove_client.sh index 33454d7512..a7eb225704 100755 --- a/packaging/tools/remove_client.sh +++ b/packaging/tools/remove_client.sh @@ -57,7 +57,7 @@ function clean_bin() { ${csudo}rm -f ${bin_link_dir}/${dumpName2} || : ${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || : ${csudo}rm -f ${bin_link_dir}/set_core || : - [ -f ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || : + [ -L ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || : if [ "$verMode" == "cluster" ] && [ "$clientName" != "$clientName2" ]; then ${csudo}rm -f ${bin_link_dir}/${clientName2} || : @@ -65,7 +65,7 @@ function clean_bin() { ${csudo}rm -f ${bin_link_dir}/${benchmarkName2} || : ${csudo}rm -f ${bin_link_dir}/${dumpName2} || : ${csudo}rm -f ${bin_link_dir}/${uninstallScript2} || : - [ -f ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || : + [ -L ${bin_link_dir}/${inspect_name} ] && ${csudo}rm -f ${bin_link_dir}/${inspect_name} || : fi }