From 6040308270b8d6c572a0c288d6422534e8ce80fe Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:46:30 -0700 Subject: [PATCH] rcp: update to use new functions --- usr/local/share/bastille/rcp.sh | 79 ++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/usr/local/share/bastille/rcp.sh b/usr/local/share/bastille/rcp.sh index a3b1cda1..7b313577 100644 --- a/usr/local/share/bastille/rcp.sh +++ b/usr/local/share/bastille/rcp.sh @@ -34,46 +34,63 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille rcp [OPTION] TARGET CONTAINER_PATH HOST_PATH" + error_notify "Usage: bastille rcp [option(s)] TARGET JAIL_PATH HOST_PATH" + cat << EOF + Options: + + -q | --quiet Suppress output. + -x | --debug Enable debug mode. + +EOF + exit 1 } -CPSOURCE="${1}" -CPDEST="${2}" +# Handle options. +OPTION="-av" +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -q|--quiet) + OPTION="-a" + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + q) OPTION="-a" ;; + x) enable_debug ;; + *) error_exit "Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done -# Handle special-case commands first. -case "$1" in -help|-h|--help) - usage - ;; --q|--quiet) - OPTION="${1}" - CPSOURCE="${2}" - CPDEST="${3}" - ;; -esac - -if [ $# -ne 2 ]; then +if [ "$#" -ne 3 ]; then usage fi -if [ "${TARGET}" = "ALL" ]; then - usage -fi +TARGET="${1}" +CPSOURCE="${2}" +CPDEST="${3}" -case "${OPTION}" in - -q|--quiet) - OPTION="-a" - ;; - *) - OPTION="-av" - ;; -esac +bastille_root_check +set_target "${TARGET}" for _jail in ${JAILS}; do info "[${_jail}]:" bastille_jail_path="${bastille_jailsdir}/${_jail}/root" - cp "${OPTION}" "${bastille_jail_path}/${CPSOURCE}" "${CPDEST}" - RETURN="$?" - echo - return "${RETURN}" + if ! cp "${OPTION}" "${bastille_jail_path}${CPSOURCE}" "${CPDEST}"; then + error_continue "RCP failed: ${bastille_jail_path}${CPSOURCE} -> ${CPDEST}" + fi done