Project

General

Profile

1 9800 aaronmk
#!/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 10009 aaronmk
upload() #usage: local_dir=... remote_url=serv:dir [swap=1] upload [opt|path]...
9
# swap: downloads instead of uploads
10 10015 aaronmk
# path: relative to *currdir*, not $local_dir. when invoking from a script, use
11
#     an absolute path (e.g. "$(dirname "${BASH_SOURCE[0]}")"/...).
12 9800 aaronmk
# requires put from https://uutils.googlecode.com/svn/trunk/bin/put
13
{
14 9893 aaronmk
	echo_func; kw_params local_dir remote_url; echo_vars swap
15 9800 aaronmk
16 9889 aaronmk
	# change path args to --includes
17 9890 aaronmk
	local has_includes= args=()
18 9889 aaronmk
	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 9890 aaronmk
			has_includes=1
25 9889 aaronmk
		fi
26
	done
27 9890 aaronmk
	set -- "${args[@]}" ${has_includes:+--exclude="**"}
28 9811 aaronmk
29 10000 aaronmk
	# use .rsync_ignore
30
	set -- --filter="dir-merge,- .rsync_ignore" "$@"
31
32 10013 aaronmk
	# 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 9890 aaronmk
	src="$local_dir" dest="$remote_url" command put "$@"
37 9800 aaronmk
}
38
39
fi