From bdfa728eaa257baee82d607bfc2de5c3ddfdff1c Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:34:21 -0700 Subject: [PATCH 1/4] pkg: auto-mode/debug-mode/notify instead of exit when done --- usr/local/share/bastille/pkg.sh | 75 +++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index e7cf23d7..12f918db 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -31,29 +31,82 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. . /usr/local/share/bastille/common.sh +. /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille pkg [-H|--host] TARGET command [args]" + error_notify "Usage: bastille pkg [option(s)] TARGET COMMAND args" + cat << EOF + Options: + + -a | --auto Auto mode. Start/stop jail(s) if required. + -H | --host Use the hosts pkg command. + -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 +USE_HOST_PKG=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -a|--auto) + AUTO=1 + shift + ;; + -H|--host) + USE_HOST_PKG=1 + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + a) AUTO=1 ;; + H) USE_HOST_PKG=1 ;; + x) enable_debug ;; + *) error_exit "Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done -if [ $# -lt 1 ]; then +if [ $# -lt 2 ]; then usage fi +TARGET="${1}" +shift + bastille_root_check +set_target "${TARGET}" errors=0 for _jail in ${JAILS}; do + info "[${_jail}]:" - bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path) + + check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then + bastille start "${_jail}" + else + error_notify "Jail is not running." + error_continue "Use [-a|--auto] to auto-start the jail." + fi + + bastille_jail_path="${bastille_jailsdir}/${_jail}/root" if [ -f "/usr/sbin/mport" ]; then if ! jexec -l -U root "${_jail}" /usr/sbin/mport "$@"; then errors=1 @@ -71,10 +124,8 @@ for _jail in ${JAILS}; do errors=1 fi fi - echo done if [ $errors -ne 0 ]; then - error_exit "Failed to apply on some jails, please check logs" - exit 1 + error_notify "Failed to apply on some jails, please check logs" fi From 4b35b2ad471f3d90769f86190b0706f4a306efbe Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sat, 18 Jan 2025 17:37:04 -0700 Subject: [PATCH 2/4] pkg: exit on error --- usr/local/share/bastille/pkg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index 12f918db..01c1708b 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -127,5 +127,5 @@ for _jail in ${JAILS}; do done if [ $errors -ne 0 ]; then - error_notify "Failed to apply on some jails, please check logs" + error_exit "Failed to apply on some jails, please check logs" fi From 4c20155af6a1e93a80730f73c1b5953e56be9e62 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 26 Jan 2025 12:28:21 -0700 Subject: [PATCH 3/4] pkg: Usage message clarify --- usr/local/share/bastille/pkg.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index 01c1708b..2a37afbc 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -39,7 +39,7 @@ usage() { Options: -a | --auto Auto mode. Start/stop jail(s) if required. - -H | --host Use the hosts pkg command. + -H | --host Use host 'pkg'. -x | --debug Enable debug mode. EOF From 7be9934a260a9a9fcc4266ce2d8b2def7b79bedb Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 26 Jan 2025 12:30:24 -0700 Subject: [PATCH 4/4] bastille: Pkg 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 04f28e8c..93374e8f 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -164,10 +164,10 @@ version|-v|--version) help|-h|--help) usage ;; -bootstrap|clone|create|destroy|etcupdate|export|htop|import|list|mount|rdr|rename|restart|setup|start|top|umount|update|upgrade|verify) +bootstrap|clone|create|destroy|etcupdate|export|htop|import|list|mount|pkg|rdr|rename|restart|setup|start|top|umount|update|upgrade|verify) # Nothing "extra" to do for these commands. -- cwells ;; -config|cmd|console|convert|cp|edit|limits|pkg|rcp|service|stop|sysrc|tags|template|zfs) +config|cmd|console|convert|cp|edit|limits|rcp|service|stop|sysrc|tags|template|zfs) # 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'