From e7e65a059de3071d1dc91e72fe57c1d50df3e61d Mon Sep 17 00:00:00 2001 From: WANG Xu Date: Tue, 18 Mar 2025 16:23:20 +0800 Subject: [PATCH] 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