Skip to content

Commit

Permalink
rcp: update to use new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tschettervictor authored Jan 11, 2025
1 parent 228bb3b commit 6040308
Showing 1 changed file with 48 additions and 31 deletions.
79 changes: 48 additions & 31 deletions usr/local/share/bastille/rcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
CPSOURCE="${1}"
CPDEST="${2}"
-q | --quiet Suppress output.
-x | --debug Enable debug mode.
# Handle special-case commands first.
case "$1" in
help|-h|--help)
usage
;;
-q|--quiet)
OPTION="${1}"
CPSOURCE="${2}"
CPDEST="${3}"
;;
esac
EOF
exit 1
}

if [ $# -ne 2 ]; then
usage
fi
# 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

if [ "${TARGET}" = "ALL" ]; then
if [ "$#" -ne 3 ]; then
usage
fi

case "${OPTION}" in
-q|--quiet)
OPTION="-a"
;;
*)
OPTION="-av"
;;
esac
TARGET="${1}"
CPSOURCE="${2}"
CPDEST="${3}"

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

0 comments on commit 6040308

Please sign in to comment.