setup: Add -y

This commit is contained in:
tschettervictor
2025-05-16 15:32:56 -06:00
committed by GitHub
parent 6aec9acf59
commit be4d68fcf1

View File

@@ -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
@@ -342,17 +357,49 @@ if [ $# -eq 0 ]; then
fi
# Handle options.
case "$1" in
AUTO_YES=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-f|--filesystem)
-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
-f|filesystem)
configure_filesystem
;;
-p|pf|firewall)
configure_pf
;;
-n|netgraph)
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."
@@ -370,9 +417,12 @@ case "$1" in
error_exit "Invalid selection. Please answer 'y' or 'n'"
;;
esac
fi
;;
-l|loopback)
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."
@@ -389,8 +439,12 @@ case "$1" in
error_exit "Invalid selection. Please answer 'y' or 'n'"
;;
esac
fi
;;
-s|shared)
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."
@@ -407,6 +461,7 @@ case "$1" in
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)
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}\""