From 55c54953130014b72d9f49a18ce1fd17ee2c0cf8 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 5 May 2025 13:27:08 -0600 Subject: [PATCH 1/3] pkg: Fix promt for y|n --- usr/local/share/bastille/pkg.sh | 61 ++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index d73b6857..e5f6a030 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -40,6 +40,7 @@ usage() { -a | --auto Auto mode. Start/stop jail(s) if required. -H | --host Use the hosts 'pkg' instead of the jails. + -y | --yes Assume always yes for pkg command. Do not prompt. -x | --debug Enable debug mode. EOF @@ -48,6 +49,7 @@ EOF # Handle options. AUTO=0 +AUTO_YES=0 USE_HOST_PKG=0 while [ "$#" -gt 0 ]; do case "${1}" in @@ -62,6 +64,10 @@ while [ "$#" -gt 0 ]; do USE_HOST_PKG=1 shift ;; + -y|--yes) + AUTO_YES=1 + shift + ;; -x|--debug) enable_debug shift @@ -71,6 +77,7 @@ while [ "$#" -gt 0 ]; do case ${_opt} in a) AUTO=1 ;; H) USE_HOST_PKG=1 ;; + y) AUTO_YES=1 ;; x) enable_debug ;; *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; esac @@ -89,15 +96,14 @@ fi TARGET="${1}" shift + +OPTION="" +BLA="$@" bastille_root_check set_target "${TARGET}" -errors=0 - -for _jail in ${JAILS}; do - - ( +pkg_run_command() { # Validate jail state check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then @@ -120,18 +126,49 @@ for _jail in ${JAILS}; do if ! jexec -l "${_jail}" /usr/bin/apt "$@"; then errors=1 fi - elif [ "${USE_HOST_PKG}" = 1 ]; then - if ! /usr/sbin/pkg -j "${_jail}" "$@"; then + elif [ "${USE_HOST_PKG}" -eq 1 ]; then + if [ "${AUTO_YES}" -eq 1 ]; then + _jail_cmd="env ASSUME_ALWAYS_YES=yes /usr/sbin/pkg -j "${_jail}" "$@"" + else + _jail_cmd="/usr/sbin/pkg -j "${_jail}" "$@"" + fi + if ! ${_jail_cmd}; then errors=1 fi else - if ! jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"; then + if [ "${AUTO_YES}" -eq 1 ]; then + _jail_cmd="jexec -l -U root "${_jail}" env ASSUME_ALWAYS_YES=yes /usr/sbin/pkg "$@"" + else + _jail_cmd="jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"" + fi + if ! ${_jail_cmd}; then errors=1 fi fi - - ) & - +} + +errors=0 + +for _jail in ${JAILS}; do + + if [ "${AUTO_YES}" -eq 1 ]; then + + ( + + pkg_run_command "$@" + + ) & + + else + + ( + + pkg_run_command "$@" + + ) + + fi + bastille_running_jobs "${bastille_process_limit}" done @@ -141,4 +178,4 @@ if [ $errors -ne 0 ]; then error_exit "[ERROR]: Failed to apply on some jails, please check logs" else echo -fi \ No newline at end of file +fi From bd251f98feb98a36c03184c091c81b05b61c39cd Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 5 May 2025 13:27:56 -0600 Subject: [PATCH 2/3] Update pkg.rst --- docs/chapters/subcommands/pkg.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/chapters/subcommands/pkg.rst b/docs/chapters/subcommands/pkg.rst index d27badd7..5b00ca88 100644 --- a/docs/chapters/subcommands/pkg.rst +++ b/docs/chapters/subcommands/pkg.rst @@ -112,4 +112,5 @@ you can fully leverage the pkg manager. This means, ``install``, ``update``, -a | --auto Auto mode. Start/stop jail(s) if required. -H | --host Use the hosts 'pkg' instead of the jails. + -y | --yes Assume always yes for pkg. Do not prompt. -x | --debug Enable debug mode. From 768ae1bbdef3d3f39d7ff7ff291687e207238eba Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 5 May 2025 13:32:05 -0600 Subject: [PATCH 3/3] pkg: Fix shellcheck --- usr/local/share/bastille/pkg.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index e5f6a030..2e674f44 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -96,9 +96,6 @@ fi TARGET="${1}" shift - -OPTION="" -BLA="$@" bastille_root_check set_target "${TARGET}" @@ -128,18 +125,18 @@ pkg_run_command() { fi elif [ "${USE_HOST_PKG}" -eq 1 ]; then if [ "${AUTO_YES}" -eq 1 ]; then - _jail_cmd="env ASSUME_ALWAYS_YES=yes /usr/sbin/pkg -j "${_jail}" "$@"" + _jail_cmd="env ASSUME_ALWAYS_YES=yes /usr/sbin/pkg -j ${_jail} $@" else - _jail_cmd="/usr/sbin/pkg -j "${_jail}" "$@"" + _jail_cmd="/usr/sbin/pkg -j ${_jail} $@" fi if ! ${_jail_cmd}; then errors=1 fi else if [ "${AUTO_YES}" -eq 1 ]; then - _jail_cmd="jexec -l -U root "${_jail}" env ASSUME_ALWAYS_YES=yes /usr/sbin/pkg "$@"" + _jail_cmd="jexec -l -U root ${_jail} env ASSUME_ALWAYS_YES=yes /usr/sbin/pkg $@" else - _jail_cmd="jexec -l -U root "${_jail}" /usr/sbin/pkg "$@"" + _jail_cmd="jexec -l -U root ${_jail} /usr/sbin/pkg $@" fi if ! ${_jail_cmd}; then errors=1