bpakk: Change `-w` option to `-s`/`--size`
[sunny256-utils.git] / Local / s10 / ft
blob566e0acca15a5e0facb4a49536886c34fc97fd39
1 #!/bin/sh
3 #==============================================================================
4 # ft
5 # File ID: e2b4cbf2-baff-11e8-97b6-c75b54f489f8
7 # Send files from $url to $dest with rsync, retry until it's done.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=ft
14 VERSION=0.4.1
16 rcfile=~/.ftrc
18 opt_append=0
19 opt_copy=0
20 opt_help=0
21 opt_quiet=0
22 opt_verbose=0
23 while test -n "$1"; do
24 case "$1" in
25 -a|--append) opt_append=1; shift ;;
26 -c|--copy) opt_copy=1; shift ;;
27 -h|--help) opt_help=1; shift ;;
28 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
29 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
30 --version) echo $progname $VERSION; exit 0 ;;
31 --) shift; break ;;
33 if printf '%s\n' "$1" | grep -q ^-; then
34 echo "$progname: $1: Unknown option" >&2
35 exit 1
36 else
37 break
39 break ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Usage: $progname [options] [ -- rsync_options ]
50 Options:
52 -a, --append
53 Don't check downloaded data, only append data to the end of files.
54 Use with care.
55 -c, --copy
56 Don't use the --inplace option with rsync, write to a copy of the
57 destination file before overwriting it.
58 -h, --help
59 Show this help.
60 -q, --quiet
61 Be more quiet. Can be repeated to increase silence.
62 -v, --verbose
63 Increase level of verbosity. Can be repeated.
64 --version
65 Print version information.
67 Create the rcfile and define url (ssh address of source directory) and
68 dest (local directory). For example:
70 url=user@fromhost:/home/user/tel/
71 dest=/sdcard/tel/
73 END
74 exit 0
77 cmd_rsync="rsync -rmvLPzz --timeout=15"
79 unset url dest
80 test -e "$rcfile" && . "$rcfile"
82 if test -z "$url" -o -z "$dest"; then
83 echo $progname: url or dest not defined in $rcfile >&2
84 exit 1
87 if test "$opt_append" = "1"; then
88 append_str="--append"
89 else
90 append_str=""
92 if test "$opt_copy" = "1"; then
93 copy_str=""
94 else
95 copy_str="--inplace"
97 ps | grep -v "grep $cmd_rsync" | grep "$cmd_rsync" && exit 1
98 until $cmd_rsync $append_str $copy_str $url $dest "$@"; do
99 date;
100 sleep 2;
101 done
103 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :