diff --git a/usr/local/share/bastille/setup.sh b/usr/local/share/bastille/setup.sh index eee1d7e2..06c369bd 100644 --- a/usr/local/share/bastille/setup.sh +++ b/usr/local/share/bastille/setup.sh @@ -33,7 +33,22 @@ . /usr/local/share/bastille/common.sh usage() { - error_exit "Usage: bastille setup [-b|bridge] [-f|--filesystem] [-l|loopback] [-p|pf|firewall] [-s|shared] [-v|vnet] [-z|zfs|storage]" + error_notify "Usage: bastille setup [option(s)] [-b|bridge]" + error_notify " [-f|filesystem]" + error_notify " [-l|loopback]" + error_notify " [-p|pf|firewall]" + error_notify " [-s|shared]" + error_notify " [-v|vnet]" + error_notify " [-z|zfs|storage]" + cat << EOF + + Options: + + -y | --yes Assume always yes on prompts. + -x | --debug Enable debug mode. + +EOF + exit 1 } # Check for too many args @@ -57,7 +72,7 @@ configure_filesystem() { fi chmod 0750 "${bastille_prefix}" # Make sure the dataset is mounted in the proper place - elif [ -d "${bastille_prefix}" ]; then + elif [ -d "${bastille_prefix}" ] && checkyesno bastille_zfs_enable; then if ! zfs list "${bastille_zfs_zpool}/${bastille_zfs_prefix}" >/dev/null; then zfs create ${bastille_zfs_options} -o mountpoint="${bastille_prefix}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}" elif [ "$(zfs get -H -o value mountpoint ${bastille_zfs_zpool}/${bastille_zfs_prefix})" != "${bastille_prefix}" ]; then @@ -341,72 +356,112 @@ if [ $# -eq 0 ]; then exit 0 fi +# Handle options. +AUTO_YES=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -y|--yes) + AUTO_YES=1 + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + y) AUTO_YES=1 ;; + x) enable_debug ;; + *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done + # Handle options. case "$1" in - -h|--help|help) - usage - ;; - -f|--filesystem) + -f|filesystem) configure_filesystem ;; -p|pf|firewall) configure_pf ;; -n|netgraph) - warn "[WARNING]: Bastille only allows using either 'if_bridge' or 'netgraph'" - warn "as VNET network options. You CANNOT use both on the same system. If you have" - warn "already started using bastille with 'if_bridge' do not continue." - # shellcheck disable=SC3045 - read -p "Do you really want to continue setting up netgraph for Bastille? [y|n]:" _answer - case "${_answer}" in - [Yy]|[Yy][Ee][Ss]) - configure_vnet - configure_netgraph - ;; - [Nn]|[Nn][Oo]) - error_exit "Netgraph setup cancelled." - ;; - *) - error_exit "Invalid selection. Please answer 'y' or 'n'" - ;; - esac + if [ "${AUTO_YES}" -eq 1 ]; then + configure_vnet + configure_netgraph + else + warn "[WARNING]: Bastille only allows using either 'if_bridge' or 'netgraph'" + warn "as VNET network options. You CANNOT use both on the same system. If you have" + warn "already started using bastille with 'if_bridge' do not continue." + # shellcheck disable=SC3045 + read -p "Do you really want to continue setting up netgraph for Bastille? [y|n]:" _answer + case "${_answer}" in + [Yy]|[Yy][Ee][Ss]) + configure_vnet + configure_netgraph + ;; + [Nn]|[Nn][Oo]) + error_exit "Netgraph setup cancelled." + ;; + *) + error_exit "Invalid selection. Please answer 'y' or 'n'" + ;; + esac + fi ;; - -l|loopback) - warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" - warn "interface to be configured ant one time. If you continue, the 'shared'" - warn "interface will be disabled, and the 'loopback' interface will be used as default." - # shellcheck disable=SC3045 - read -p "Do you really want to continue setting up the loopback interface? [y|n]:" _answer - case "${_answer}" in - [Yy]|[Yy][Ee][Ss]) - configure_loopback_interface - ;; - [Nn]|[Nn][Oo]) - error_exit "Loopback interface setup cancelled." - ;; - *) - error_exit "Invalid selection. Please answer 'y' or 'n'" - ;; - esac + if [ "${AUTO_YES}" -eq 1 ]; then + configure_loopback_interface + else + warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" + warn "interface to be configured ant one time. If you continue, the 'shared'" + warn "interface will be disabled, and the 'loopback' interface will be used as default." + # shellcheck disable=SC3045 + read -p "Do you really want to continue setting up the loopback interface? [y|n]:" _answer + case "${_answer}" in + [Yy]|[Yy][Ee][Ss]) + configure_loopback_interface + ;; + [Nn]|[Nn][Oo]) + error_exit "Loopback interface setup cancelled." + ;; + *) + error_exit "Invalid selection. Please answer 'y' or 'n'" + ;; + esac + fi ;; -s|shared) - warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" - warn "interface to be configured at one time. If you continue, the 'loopback'" - warn "interface will be disabled, and the shared interface will be used as default." - # shellcheck disable=SC3045 - read -p "Do you really want to continue setting up the shared interface? [y|n]:" _answer - case "${_answer}" in - [Yy]|[Yy][Ee][Ss]) - configure_shared_interface - ;; - [Nn]|[Nn][Oo]) - error_exit "Shared interface setup cancelled." - ;; - *) - error_exit "Invalid selection. Please answer 'y' or 'n'" - ;; - esac + if [ "${AUTO_YES}" -eq 1 ]; then + configure_shared_interface + else + warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'" + warn "interface to be configured at one time. If you continue, the 'loopback'" + warn "interface will be disabled, and the shared interface will be used as default." + # shellcheck disable=SC3045 + read -p "Do you really want to continue setting up the shared interface? [y|n]:" _answer + case "${_answer}" in + [Yy]|[Yy][Ee][Ss]) + configure_shared_interface + ;; + [Nn]|[Nn][Oo]) + error_exit "Shared interface setup cancelled." + ;; + *) + error_exit "Invalid selection. Please answer 'y' or 'n'" + ;; + esac + fi ;; -z|zfs|storage) configure_storage @@ -415,8 +470,12 @@ case "$1" in configure_vnet ;; -b|bridge) - configure_vnet - configure_bridge + if [ "${AUTO_YES}" -eq 1 ]; then + error_exit "[ERROR]: [-b|bridge] does not support [-y|--yes]." + else + configure_vnet + configure_bridge + fi ;; *) error_exit "[ERROR]: Unknown option: \"${1}\""