#!/bin/bash
#  net/tool/rsync - ``rsync`` Command Support

set -e


######
# Native Dependencies

net_tool_rsync_client_packages=( rsync )


######
# Library Configuration

net_tool_rsync_config_init() {
	# $rsync_verbose - If ``true``, adds the ``--verbose`` option.
	# Default: ``false``
	lib_setting_vars rsync_verbose

	# $rsync_readable - If ``true``, adds the ``--human-readable`` option.
	# Default: ``true``
	lib_setting_vars rsync_readable

	# $rsync_dry_run - If ``true``, adds the ``--dry-run`` option.
	# Default: ``false``
	lib_setting_vars rsync_dry_run

	# $rsync_partdir - Path to use for the ``--partial-dir`` option.
	# Default: ``${package_name}-rsync-partials``
	lib_setting_vars -ro rsync_partdir

	# $rsync_bwlimit - Limits the bandwidth used during the transfer.
	# Default: Not set (no limit).
	lib_setting_vars -ro --null rsync_bwlimit

	net_tool_rsync_config_check
}

net_tool_rsync_config_check() {
	rsync_verbose="${rsync_verbose:-false}"
	rsync_readable="${rsync_readable:-true}"
	rsync_dry_run="${rsync_dry_run:-false}"
	rsync_partdir="${rsync_partdir:-.${package_name}-rsync-partials}"
}


######
# Public Interface

# rsync_run() - Runs the ``rsync`` command with the options specified
# by the `Library Configuration`_ settings.
rsync_run() {
	local -a opts=()

	opts+=( --partial-dir="$rsync_partdir" )

	! $rsync_verbose || opts+=( --verbose )
	! $rsync_dry_run || opts+=( --dry-run )
	! $rsync_readable || opts+=( --human-readable )
	[ -z "$rsync_bwlimit" ] || opts+=( --bwlimit "$rsync_bwlimit" )
	[ -z "$ssh_port" ] || opts+=( -e "ssh -p $ssh_port" )
	run rsync "${opts[@]}" "$@"
}

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:35:52 PDT 2017 by mcsh d14 v0.23.0.