From fab14ffe7c72dae03544ed7e53dacce33e66a857 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sat, 1 Mar 2025 21:14:56 -0700 Subject: [PATCH] bastille: Allow setting config file --- usr/local/bin/bastille | 61 +++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index d347952c..9be4f78f 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -31,6 +31,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin +. /usr/local/share/bastille/common.sh ## check for config existence bastille_conf_check() { @@ -54,12 +55,6 @@ bastille_conf_check() { fi } -bastille_conf_check - -## we only load this if conf_check passes -. /usr/local/share/bastille/common.sh -. /usr/local/etc/bastille/bastille.conf - ## bastille_prefix should be 0750 ## this restricts file system access to privileged users bastille_perms_check() { @@ -72,11 +67,6 @@ bastille_perms_check() { fi } -bastille_perms_check - -## version -BASTILLE_VERSION="0.13.20250126" - usage() { cat << EOF Bastille is an open-source system for automating deployment and management of @@ -131,6 +121,48 @@ EOF exit 1 } +bastille_conf_check +bastille_perms_check + +BASTILLE_VERSION="0.13.20250126" + +# Handle options +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + version|-v|--version) + info "${BASTILLE_VERSION}" + exit 0 + ;; + -c|--config) + BASTILLE_CONFIG="${2}" + if [ -r "${BASTILLE_CONFIG}" ]; then + info "Using custom config: ${BASTILLE_CONFIG}" + elif [ -r "/usr/local/etc/bastille/${BASTILLE_CONFIG}" ]; then + BASTILLE_CONFIG="/usr/local/etc/bastille/${BASTILLE_CONFIG}" + info "Using custom config: ${BASTILLE_CONFIG}" + else + error_exit "Not a valid config file: ${BASTILLE_CONFIG}" + fi + shift 2 + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + x) enable_debug ;; + a) AUTO=1 ;; + *) error_exit "Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done if [ "$#" -lt 1 ]; then usage else @@ -140,13 +172,6 @@ fi # Handle special-case commands first. case "${CMD}" in - version|-v|--version) - info "${BASTILLE_VERSION}" - exit 0 - ;; - help|-h|--help) - usage - ;; bootstrap| \ clone| \ cmd| \