From 268d16e638655eaa215c8a3c3fa68b66c6db97f6 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:01:52 -0700 Subject: [PATCH 1/5] convert: Implement new functions --- usr/local/share/bastille/convert.sh | 58 +++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/usr/local/share/bastille/convert.sh b/usr/local/share/bastille/convert.sh index d22c9708..d5d5b582 100644 --- a/usr/local/share/bastille/convert.sh +++ b/usr/local/share/bastille/convert.sh @@ -34,21 +34,63 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille convert TARGET" + error_notify "Usage: bastille convert [option(s)] TARGET" + + cat << EOF + Options: + + -a | --auto Auto mode. Start/stop jail(s) if required. + -x | --debug Enable debug mode. + +EOF + exit 1 } -# Handle special-case commands first. -case "$1" in -help|-h|--help) - usage - ;; -esac +# Handle options. +AUTO=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -a|--auto) + AUTO=1 + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + a) AUTO=1 ;; + x) enable_debug ;; + *) error_exit "Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done -if [ $# -ne 0 ]; then +if [ "$#" -ne 1 ]; then usage fi +TARGET="${1}" + bastille_root_check +set_target_single "${TARGET}" +check_target_is_stopped "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then + bastille stop "${TARGET}" +else + error_notify "Jail is running." + error_exit "Use [-a|--auto] to auto-stop the jail." +fi convert_symlinks() { # Work with the symlinks, revert on first cp error From 65b8eea86f5f33499a4fe3368127b754a178e55f Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:03:43 -0700 Subject: [PATCH 2/5] zfs: Implement new functions --- usr/local/share/bastille/zfs.sh | 92 +++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/usr/local/share/bastille/zfs.sh b/usr/local/share/bastille/zfs.sh index 3ba50792..8ffef062 100644 --- a/usr/local/share/bastille/zfs.sh +++ b/usr/local/share/bastille/zfs.sh @@ -34,7 +34,14 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille zfs TARGET [set|get|snap] [key=value|date]'" + error_notify "Usage: bastille zfs TARGET [set|get|snap|destroy_snap|df|usage] [key=value|date]" + cat << EOF + Options: + + -x | --debug Enable debug mode. + +EOF + exit 1 } zfs_snapshot() { @@ -79,47 +86,68 @@ for _jail in ${JAILS}; do done } -# Handle special-case commands first. -case "$1" in -help|-h|--help) + +# 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 [ "$#" -lt 2 ]; then usage - ;; -esac +fi + +TARGET="${1}" +ACTION="${2}" bastille_root_check +set_target "${TARGET}" -## check ZFS enabled +# Check if ZFS is enabled if ! checkyesno bastille_zfs_enable; then error_exit "ZFS not enabled." fi -## check zpool defined +# Check if zpool is defined if [ -z "${bastille_zfs_zpool}" ]; then error_exit "ZFS zpool not defined." fi -if [ $# -lt 1 ]; then - usage -fi - -case "$1" in -set) - ATTRIBUTE=$2 - zfs_set_value - ;; -get) - ATTRIBUTE=$2 - zfs_get_value - ;; -snap|snapshot) - TAG=$2 - zfs_snapshot - ;; -destroy_snap|destroy_snapshot) - TAG=$2 - zfs_destroy_snapshot - ;; -df|usage) - zfs_disk_usage - ;; +case "${ACTION}" in + set) + ATTRIBUTE="${3}" + zfs_set_value + ;; + get) + ATTRIBUTE="${3}" + zfs_get_value + ;; + snap|snapshot) + TAG="${3}" + zfs_snapshot + ;; + destroy_snap|destroy_snapshot) + TAG="${3}" + zfs_destroy_snapshot + ;; + df|usage) + zfs_disk_usage + ;; + *) + usage + ;; esac From 392b581dd27699ee1a7c05e7cf22a0e855f1dce0 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:05:26 -0700 Subject: [PATCH 3/5] docs: Update convert for new functions --- docs/chapters/subcommands/convert.rst | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/chapters/subcommands/convert.rst b/docs/chapters/subcommands/convert.rst index c2c63e3c..32e5f5d4 100644 --- a/docs/chapters/subcommands/convert.rst +++ b/docs/chapters/subcommands/convert.rst @@ -2,15 +2,22 @@ convert ======= -To convert a thin container to a thick container use `bastille convert`. +Convert a thin jail to a thick jail. .. code-block:: shell ishmael ~ # bastille convert azkaban [azkaban]: + ... -Syntax requires only the target container to convert. +Syntax requires only the target jail to convert. .. code-block:: shell - Usage: bastille convert TARGET + ishmael ~ # bastille convert help + Usage: bastille convert [option(s)] TARGET + + Options: + + -a | --auto Auto mode. Start/stop jail(s) if required. + -x | --debug Enable debug mode. From 4de935a83171b45fa0179fd049492b1eedd01bfa Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:08:13 -0700 Subject: [PATCH 4/5] docs: Add zfs --- docs/chapters/subcommands/zfs.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 docs/chapters/subcommands/zfs.rst diff --git a/docs/chapters/subcommands/zfs.rst b/docs/chapters/subcommands/zfs.rst new file mode 100644 index 00000000..f010d16f --- /dev/null +++ b/docs/chapters/subcommands/zfs.rst @@ -0,0 +1,14 @@ +=== +zfs +=== + +Manage ZFS properties, ceate and destroy snapshots, and check ZFS usage for targeted jail(s). + +.. code-block:: shell + + ishmael ~ # bastille zfs help + Usage: bastille zfs TARGET [set|get|snap|destroy_snap|df|usage] [key=value|date] + + Options: + + -x | --debug Enable debug mode. From 5b2d70501905cba1d8355ecd7185b8919cd71d92 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 23 Feb 2025 12:09:13 -0700 Subject: [PATCH 5/5] bastille: Convert and zfs to no action commands --- usr/local/bin/bastille | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 6c5b14c6..9fc378a6 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -165,10 +165,10 @@ version|-v|--version) help|-h|--help) usage ;; -bootstrap|clone|cmd|config|console|create|cp|destroy|edit|etcupdate|export|htop|import|jcp|list|mount|pkg|rcp|rdr|rename|restart|service|setup|start|stop|sysrc|top|umount|update|upgrade|verify) +bootstrap|clone|cmd|config|console|convert|create|cp|destroy|edit|etcupdate|export|htop|import|jcp|list|mount|pkg|rcp|rdr|rename|restart|service|setup|start|stop|sysrc|top|umount|update|upgrade|verify|zfs) # Nothing "extra" to do for these commands. -- cwells ;; -convert|limits|tags|template|zfs) +limits|tags|template) # Parse the target and ensure it exists. -- cwells if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells PARAMS='help'