refactor: silent mode
Signed-off-by: WANG Xu <feici02@outlook.com>
This commit is contained in:
parent
e8cc3fcc9c
commit
e7e65a059d
|
@ -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 <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"
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue