Project

General

Profile

1
#!/bin/bash -e
2
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
3

    
4
if self_not_included; then
5

    
6
alias use_sync='declare prefix=sync_; import_vars; unset prefix'
7

    
8
upload() #usage: local_dir=... remote_url=serv:dir [swap=1] upload [opt|path]...
9
# swap: downloads instead of uploads
10
# path: relative to *currdir*, not $local_dir. when invoking from a script, use
11
#     an absolute path (e.g. "$(dirname "${BASH_SOURCE[0]}")"/...).
12
# requires put from https://uutils.googlecode.com/svn/trunk/bin/put
13
{
14
	echo_func; kw_params local_dir remote_url; echo_vars swap
15
	
16
	# change path args to --includes
17
	local has_includes= args=()
18
	local a; for a in "$@"; do
19
		if starts_with -- "$a"; then args+=("$a") # option, so leave as is
20
		else # path
21
			# also need to --include parent dirs for each --include path
22
			path_parents "$(base_dir="$local_dir" canon_rel_path "$a")"
23
			args+=("${dirs[@]/#/--include=/}") # prepend each with --include=/
24
			has_includes=1
25
		fi
26
	done
27
	set -- "${args[@]}" ${has_includes:+--exclude="**"}
28
	
29
	# use .rsync_ignore
30
	set -- --filter="dir-merge,- .rsync_ignore" "$@"
31
	
32
	# use directional .rsync_filter
33
	local filter_type=upload; if test "$swap"; then filter_type=download; fi
34
	set -- --filter="dir-merge .rsync_filter.$filter_type" "$@"
35
	
36
	src="$local_dir" dest="$remote_url" command put "$@"
37
}
38

    
39
fi
(8-8/10)