Hongyi Zhao <
hongy...@gmail.com> wrote:
> In my case, I first use the /home/werner/.popt file to define the alias -
> Z as follows:
>
> $ cat /home/werner/.popt
> rsync alias -Z --no-p --no-g --chmod=ugo=rwX
>
> Then I run rsync with the alias -Z like this:
>
> $ rsync -avZ --temp-dir=/tmp /media/cdrom/pool/ /home/werner/Desktop/111/
>
> Now, suppose I want to do some more complicated job including the above
> codes in it, I think it's a more easier way first define the
> alias_varialbe in the script then invoke it by using rsync command in the
> same script. I just want to know how to do the above things like this
> way.
>
> BTW, as you have pointed that, we can simply invoke the rsync like for my
> purpose:
>
> rsync -av --no-p --no-g --chmod=ugo=rwX --temp-dir=/tmp /media/cdrom/
> pool/ /home/werner/Desktop/111/
>
> But for a more complicated case, say, I want to do server different rsync
> jobs with different alias options in one script, according to the
> described method here, I must define all of the alias options in /home/
> werner/.popt, in this way, I must remember all of the these definitions
> in mind when I want to invoke them. While if I can define these alias
> options in-place of the shell script which use all of these alias
> options, I think it will be more convenient to use.
Modify rsync to allow a popt initialisation file to be specified in an
environment variable. Use like this:
echo "alias rsync -Z --no-p --no-g --chmod=ugu=rwX" > poptrc1
RSYNC_POPTRC=poptrc1 rsync -aZv ...
echo "alias rsync -Z --chmod=ugu=rwX" > poptrc2
RSYNC_POPTRC=poptrc2 rsync -aZ ...
# to ignore system popt rc files
RSYNC_POPTRC=/dev/null rsync ...
and so on.
The following patch (between #v+ and #v-) contains tab characters. You
may need to use patch's -l (that's a lower-case L) argument if they are
converted to spaces in transit.
As usual, if this breaks you get to keep all the pieces.
#v+
--- rsync-3.0.9/options.c.orig 2011-09-13 23:41:26.000000000 +0100
+++ rsync-3.0.9/options.c 2012-10-31 09:22:38.000000000 +0000
@@ -898,6 +898,7 @@
const char *arg, **argv = *argv_p;
int argc = *argc_p;
int opt;
+ const char *rcf;
if (ref && *ref)
set_refuse_options(ref);
@@ -921,8 +922,12 @@
if (pc)
poptFreeContext(pc);
pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
- if (!am_server)
- poptReadDefaultConfig(pc, 0);
+ if (!am_server) {
+ if ((rcf = getenv("RSYNC_POPTRC")))
+ poptReadConfigFile(pc, rcf);
+ else
+ poptReadDefaultConfig(pc, 0);
+ }
while ((opt = poptGetNextOpt(pc)) != -1) {
/* most options are handled automatically by popt;
#v-