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 10030 aaronmk
upload() # usage: local_dir=... remote_url=serv:dir [swap=1] [subpath=...] \
9
# upload [opt|path]...
10 10009 aaronmk
# swap: downloads instead of uploads
11 10030 aaronmk
# subpath: relative to *currdir*, not $local_dir as in `put`
12 10015 aaronmk
# path: relative to *currdir*, not $local_dir. when invoking from a script, use
13
#     an absolute path (e.g. "$(dirname "${BASH_SOURCE[0]}")"/...).
14 9800 aaronmk
# requires put from https://uutils.googlecode.com/svn/trunk/bin/put
15
{
16 9893 aaronmk
	echo_func; kw_params local_dir remote_url; echo_vars swap
17 9800 aaronmk
18 10030 aaronmk
	# make subpath relative to currdir
19
	if test "$subpath"; then
20
		local subpath="$(base_dir="$local_dir" canon_rel_path "$subpath")"
21
		if test "$subpath" = .; then unset subpath; fi
22
	fi
23
24 9889 aaronmk
	# change path args to --includes
25 9890 aaronmk
	local has_includes= args=()
26 9889 aaronmk
	local a; for a in "$@"; do
27
		if starts_with -- "$a"; then args+=("$a") # option, so leave as is
28
		else # path
29
			# also need to --include parent dirs for each --include path
30
			path_parents "$(base_dir="$local_dir" canon_rel_path "$a")"
31
			args+=("${dirs[@]/#/--include=/}") # prepend each with --include=/
32 9890 aaronmk
			has_includes=1
33 9889 aaronmk
		fi
34
	done
35 9890 aaronmk
	set -- "${args[@]}" ${has_includes:+--exclude="**"}
36 9811 aaronmk
37 10000 aaronmk
	# use .rsync_ignore
38
	set -- --filter="dir-merge,- .rsync_ignore" "$@"
39
40 10013 aaronmk
	# use directional .rsync_filter
41
	local filter_type=upload; if test "$swap"; then filter_type=download; fi
42 10038 aaronmk
	set -- --filter="dir-merge .rsync_filter.$(hostname -s).$filter_type" \
43
	       --filter="dir-merge .rsync_filter.$filter_type" "$@"
44 10013 aaronmk
45 9890 aaronmk
	src="$local_dir" dest="$remote_url" command put "$@"
46 9800 aaronmk
}
47
48
fi