mirror of
https://github.com/hackacad/bastille.git
synced 2025-12-22 10:10:46 +01:00
setup: Add -y
This commit is contained in:
@@ -33,7 +33,22 @@
|
|||||||
. /usr/local/share/bastille/common.sh
|
. /usr/local/share/bastille/common.sh
|
||||||
|
|
||||||
usage() {
|
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
|
# Check for too many args
|
||||||
@@ -57,7 +72,7 @@ configure_filesystem() {
|
|||||||
fi
|
fi
|
||||||
chmod 0750 "${bastille_prefix}"
|
chmod 0750 "${bastille_prefix}"
|
||||||
# Make sure the dataset is mounted in the proper place
|
# 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
|
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}"
|
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
|
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
|
exit 0
|
||||||
fi
|
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.
|
# Handle options.
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help|help)
|
-f|filesystem)
|
||||||
usage
|
|
||||||
;;
|
|
||||||
-f|--filesystem)
|
|
||||||
configure_filesystem
|
configure_filesystem
|
||||||
;;
|
;;
|
||||||
-p|pf|firewall)
|
-p|pf|firewall)
|
||||||
configure_pf
|
configure_pf
|
||||||
;;
|
;;
|
||||||
-n|netgraph)
|
-n|netgraph)
|
||||||
warn "[WARNING]: Bastille only allows using either 'if_bridge' or 'netgraph'"
|
if [ "${AUTO_YES}" -eq 1 ]; then
|
||||||
warn "as VNET network options. You CANNOT use both on the same system. If you have"
|
configure_vnet
|
||||||
warn "already started using bastille with 'if_bridge' do not continue."
|
configure_netgraph
|
||||||
# shellcheck disable=SC3045
|
else
|
||||||
read -p "Do you really want to continue setting up netgraph for Bastille? [y|n]:" _answer
|
warn "[WARNING]: Bastille only allows using either 'if_bridge' or 'netgraph'"
|
||||||
case "${_answer}" in
|
warn "as VNET network options. You CANNOT use both on the same system. If you have"
|
||||||
[Yy]|[Yy][Ee][Ss])
|
warn "already started using bastille with 'if_bridge' do not continue."
|
||||||
configure_vnet
|
# shellcheck disable=SC3045
|
||||||
configure_netgraph
|
read -p "Do you really want to continue setting up netgraph for Bastille? [y|n]:" _answer
|
||||||
;;
|
case "${_answer}" in
|
||||||
[Nn]|[Nn][Oo])
|
[Yy]|[Yy][Ee][Ss])
|
||||||
error_exit "Netgraph setup cancelled."
|
configure_vnet
|
||||||
;;
|
configure_netgraph
|
||||||
*)
|
;;
|
||||||
error_exit "Invalid selection. Please answer 'y' or 'n'"
|
[Nn]|[Nn][Oo])
|
||||||
;;
|
error_exit "Netgraph setup cancelled."
|
||||||
esac
|
;;
|
||||||
|
*)
|
||||||
|
error_exit "Invalid selection. Please answer 'y' or 'n'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-l|loopback)
|
-l|loopback)
|
||||||
warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'"
|
if [ "${AUTO_YES}" -eq 1 ]; then
|
||||||
warn "interface to be configured ant one time. If you continue, the 'shared'"
|
configure_loopback_interface
|
||||||
warn "interface will be disabled, and the 'loopback' interface will be used as default."
|
else
|
||||||
# shellcheck disable=SC3045
|
warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'"
|
||||||
read -p "Do you really want to continue setting up the loopback interface? [y|n]:" _answer
|
warn "interface to be configured ant one time. If you continue, the 'shared'"
|
||||||
case "${_answer}" in
|
warn "interface will be disabled, and the 'loopback' interface will be used as default."
|
||||||
[Yy]|[Yy][Ee][Ss])
|
# shellcheck disable=SC3045
|
||||||
configure_loopback_interface
|
read -p "Do you really want to continue setting up the loopback interface? [y|n]:" _answer
|
||||||
;;
|
case "${_answer}" in
|
||||||
[Nn]|[Nn][Oo])
|
[Yy]|[Yy][Ee][Ss])
|
||||||
error_exit "Loopback interface setup cancelled."
|
configure_loopback_interface
|
||||||
;;
|
;;
|
||||||
*)
|
[Nn]|[Nn][Oo])
|
||||||
error_exit "Invalid selection. Please answer 'y' or 'n'"
|
error_exit "Loopback interface setup cancelled."
|
||||||
;;
|
;;
|
||||||
esac
|
*)
|
||||||
|
error_exit "Invalid selection. Please answer 'y' or 'n'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
-s|shared)
|
-s|shared)
|
||||||
warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'"
|
if [ "${AUTO_YES}" -eq 1 ]; then
|
||||||
warn "interface to be configured at one time. If you continue, the 'loopback'"
|
configure_shared_interface
|
||||||
warn "interface will be disabled, and the shared interface will be used as default."
|
else
|
||||||
# shellcheck disable=SC3045
|
warn "[WARNING]: Bastille only allows using either the 'loopback' or 'shared'"
|
||||||
read -p "Do you really want to continue setting up the shared interface? [y|n]:" _answer
|
warn "interface to be configured at one time. If you continue, the 'loopback'"
|
||||||
case "${_answer}" in
|
warn "interface will be disabled, and the shared interface will be used as default."
|
||||||
[Yy]|[Yy][Ee][Ss])
|
# shellcheck disable=SC3045
|
||||||
configure_shared_interface
|
read -p "Do you really want to continue setting up the shared interface? [y|n]:" _answer
|
||||||
;;
|
case "${_answer}" in
|
||||||
[Nn]|[Nn][Oo])
|
[Yy]|[Yy][Ee][Ss])
|
||||||
error_exit "Shared interface setup cancelled."
|
configure_shared_interface
|
||||||
;;
|
;;
|
||||||
*)
|
[Nn]|[Nn][Oo])
|
||||||
error_exit "Invalid selection. Please answer 'y' or 'n'"
|
error_exit "Shared interface setup cancelled."
|
||||||
;;
|
;;
|
||||||
esac
|
*)
|
||||||
|
error_exit "Invalid selection. Please answer 'y' or 'n'"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
-z|zfs|storage)
|
-z|zfs|storage)
|
||||||
configure_storage
|
configure_storage
|
||||||
@@ -415,8 +470,12 @@ case "$1" in
|
|||||||
configure_vnet
|
configure_vnet
|
||||||
;;
|
;;
|
||||||
-b|bridge)
|
-b|bridge)
|
||||||
configure_vnet
|
if [ "${AUTO_YES}" -eq 1 ]; then
|
||||||
configure_bridge
|
error_exit "[ERROR]: [-b|bridge] does not support [-y|--yes]."
|
||||||
|
else
|
||||||
|
configure_vnet
|
||||||
|
configure_bridge
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error_exit "[ERROR]: Unknown option: \"${1}\""
|
error_exit "[ERROR]: Unknown option: \"${1}\""
|
||||||
|
|||||||
Reference in New Issue
Block a user