Merge pull request #1021 from BastilleBSD/tschettervictor-patch-1

pkg: Fix promt for y|n
This commit is contained in:
Barry McCormick
2025-05-05 12:49:30 -07:00
committed by GitHub
2 changed files with 47 additions and 12 deletions

View File

@@ -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.

View File

@@ -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
@@ -93,11 +100,7 @@ shift
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 +123,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 +175,4 @@ if [ $errors -ne 0 ]; then
error_exit "[ERROR]: Failed to apply on some jails, please check logs"
else
echo
fi
fi