From 0d5b92c05226b4bbe42fe35913dc0862a69dcbc8 Mon Sep 17 00:00:00 2001 From: Juan David Hurtado G Date: Sun, 29 Dec 2024 15:22:17 -0500 Subject: [PATCH] Improve bastille.conf handling with user prompt for creation Replaced ineffective default configuration generation logic with a user-interactive prompt. Users can now choose to create the configuration file with default values if it is missing, ensuring better control and clarity. Removed redundant code from the setup script to streamline execution. --- usr/local/bin/bastille | 14 ++++++++++++-- usr/local/share/bastille/setup.sh | 7 ------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index dd9cbb25..98cd52a1 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -32,10 +32,20 @@ PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin . /usr/local/share/bastille/common.sh -## check for config existance +## check for config existence bastille_conf_check() { if [ ! -r "/usr/local/etc/bastille/bastille.conf" ]; then - error_exit "Missing Configuration" + warn "Configuration file not found. Do yu want to create it with default values? [y/N]" + read answer + case "${answer}" in + [Nn][Oo]|[Nn]|"") + error_exit "No configuration file has been generated. Exiting." + ;; + [Yy][Ee][Ss]|[Yy]) + cp /usr/local/etc/bastille/bastille.conf.sample /usr/local/etc/bastille/bastille.conf + info "Configuration file has been generated. Continuing with default values" + ;; + esac fi } diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index f6153e5b..b069ea32 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -30,13 +30,6 @@ bastille_config="/usr/local/etc/bastille/bastille.conf" . /usr/local/share/bastille/common.sh - -# TODO: This not going to take effect since Bastille checks the file -# before running this subcommand. We will need to check an strategy. -if [ ! -f "${bastille_config}" ]; then - cp /usr/local/etc/bastille/bastille.conf.sample ${bastille_config} -fi - # shellcheck source=/usr/local/etc/bastille/bastille.conf . ${bastille_config}