pkg: Fix promt for y|n

This commit is contained in:
tschettervictor
2025-05-05 13:27:08 -06:00
committed by GitHub
parent b440678cc2
commit 55c5495313

View File

@@ -40,6 +40,7 @@ usage() {
-a | --auto Auto mode. Start/stop jail(s) if required. -a | --auto Auto mode. Start/stop jail(s) if required.
-H | --host Use the hosts 'pkg' instead of the jails. -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. -x | --debug Enable debug mode.
EOF EOF
@@ -48,6 +49,7 @@ EOF
# Handle options. # Handle options.
AUTO=0 AUTO=0
AUTO_YES=0
USE_HOST_PKG=0 USE_HOST_PKG=0
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "${1}" in case "${1}" in
@@ -62,6 +64,10 @@ while [ "$#" -gt 0 ]; do
USE_HOST_PKG=1 USE_HOST_PKG=1
shift shift
;; ;;
-y|--yes)
AUTO_YES=1
shift
;;
-x|--debug) -x|--debug)
enable_debug enable_debug
shift shift
@@ -71,6 +77,7 @@ while [ "$#" -gt 0 ]; do
case ${_opt} in case ${_opt} in
a) AUTO=1 ;; a) AUTO=1 ;;
H) USE_HOST_PKG=1 ;; H) USE_HOST_PKG=1 ;;
y) AUTO_YES=1 ;;
x) enable_debug ;; x) enable_debug ;;
*) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;; *) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;;
esac esac
@@ -89,15 +96,14 @@ fi
TARGET="${1}" TARGET="${1}"
shift shift
OPTION=""
BLA="$@"
bastille_root_check bastille_root_check
set_target "${TARGET}" set_target "${TARGET}"
errors=0 pkg_run_command() {
for _jail in ${JAILS}; do
(
# Validate jail state # Validate jail state
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then 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 if ! jexec -l "${_jail}" /usr/bin/apt "$@"; then
errors=1 errors=1
fi fi
elif [ "${USE_HOST_PKG}" = 1 ]; then elif [ "${USE_HOST_PKG}" -eq 1 ]; then
if ! /usr/sbin/pkg -j "${_jail}" "$@"; 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 errors=1
fi fi
else 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 errors=1
fi fi
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}" bastille_running_jobs "${bastille_process_limit}"
done done
@@ -141,4 +178,4 @@ if [ $errors -ne 0 ]; then
error_exit "[ERROR]: Failed to apply on some jails, please check logs" error_exit "[ERROR]: Failed to apply on some jails, please check logs"
else else
echo echo
fi fi