Merge pull request #863 from BastilleBSD/new-functions-for-edit

edit: Update for new functions
This commit is contained in:
tschettervictor
2025-02-23 10:09:59 -07:00
committed by GitHub
2 changed files with 45 additions and 21 deletions

View File

@@ -2,7 +2,7 @@
edit
====
To edit container configuration use `bastille edit`.
To edit a jails configuration, use `bastille edit TARGET`.
.. code-block:: shell
@@ -13,4 +13,9 @@ be `jail.conf`. Other common filenames are `fstab` or `rctl.conf`.
.. code-block:: shell
Usage: bastille edit TARGET
ishmael ~ # bastille edit help
Usage: bastille edit [option(s)] TARGET [filename]
Options:
-x | --debug Enable debug mode.

View File

@@ -34,33 +34,52 @@
. /usr/local/etc/bastille/bastille.conf
usage() {
error_exit "Usage: bastille edit TARGET [filename]"
error_notify "Usage: bastille edit [option(s)] TARGET [filename]"
cat << EOF
Options:
-x | --debug Enable debug mode.
EOF
exit 1
}
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
esac
# Handle options.
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
usage
;;
-x|--debug)
enable_debug
shift
;;
-*)
error_notify "Unknown Option: \"${1}\""
usage
;;
*)
break
;;
esac
done
if [ $# -gt 1 ]; then
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
usage
elif [ $# -eq 1 ]; then
TARGET_FILENAME="${1}"
fi
TARGET="${1}"
if [ "$#" -eq 2 ]; then
TARGET_FILENAME="${2}"
else
TARGET_FILENAME="jail.conf"
fi
bastille_root_check
set_target_single "${TARGET}"
if [ -z "${EDITOR}" ]; then
# shellcheck disable=SC2209
EDITOR=vi
EDITOR=edit
fi
for _jail in ${JAILS}; do
if [ -n "${TARGET_FILENAME}" ]; then
"${EDITOR}" "${bastille_jailsdir}/${_jail}/${TARGET_FILENAME}"
else
"${EDITOR}" "${bastille_jailsdir}/${_jail}/jail.conf"
fi
done
"${EDITOR}" "${bastille_jailsdir}/${TARGET}/${TARGET_FILENAME}"