refactor: silent mode

Signed-off-by: WANG Xu <feici02@outlook.com>
This commit is contained in:
WANG Xu 2025-03-18 16:23:20 +08:00
parent e8cc3fcc9c
commit e7e65a059d
No known key found for this signature in database
GPG Key ID: 243B1A4F56B56F50
1 changed files with 21 additions and 20 deletions

View File

@ -236,49 +236,50 @@ function remove_data_and_config() {
[ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir} [ -d "${log_dir}" ] && ${csudo}rm -rf ${log_dir}
} }
# 解析命令行参数 function usage() {
echo -e "\nUsage: $(basename $0) [-e <yes|no>]"
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" interactive_remove="yes"
remove_flag="false"
while getopts "e:h" opt; do while getopts "e:h" opt; do
case $opt in case $opt in
e) e)
interactive_remove="no"
if [ "$OPTARG" == "yes" ]; then if [ "$OPTARG" == "yes" ]; then
interactive_remove="no" remove_flag="true"
remove_flag=false echo "Remove all the data, log, and configuration files."
echo "It will remove only the binary files and keep all the data, log, and configuration files."
elif [ "$OPTARG" == "no" ]; then elif [ "$OPTARG" == "no" ]; then
interactive_remove="no" remove_flag="false"
remove_flag=true echo "Do NOT remove the data, log, and configuration files."
echo "It will remove the binary files and all the data, log, and configuration files."
else else
echo "Invalid option for -e: $OPTARG" echo "Invalid option for -e: $OPTARG"
usage
exit 1 exit 1
fi fi
;; ;;
h) h | *)
echo "Usage: $(basename $0) -e [yes | no] " usage
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 exit 1
;; ;;
esac esac
done done
if [ "$interactive_remove" == "yes" ]; then if [ "$interactive_remove" == "yes" ]; then
echo echo -e "\nDo you want to remove all the data, log and configuration files? [y/n]"
echo "Do you want to remove all the data, log and configuration files? [y/n]"
read answer read answer
remove_flag=false
if [ X$answer == X"y" ] || [ X$answer == X"Y" ]; then 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" confirmMsg="I confirm that I would like to delete all data, log and configuration files"
echo "Please enter '${confirmMsg}' to continue" echo "Please enter '${confirmMsg}' to continue"
read answer read answer
if [ X"$answer" == X"${confirmMsg}" ]; then if [ X"$answer" == X"${confirmMsg}" ]; then
remove_flag=true remove_flag="true"
else else
echo "answer doesn't match, skip this step" echo "answer doesn't match, skip this step"
fi fi