install.sh: improve @basedir@ installation substitution
commit533f8fa1bfa75f6cf8f84c6681e685fda8302db4
authorKyle J. McKay <mackyle@gmail.com>
Tue, 28 Nov 2017 20:59:27 +0000 (28 12:59 -0800)
committerKyle J. McKay <mackyle@gmail.com>
Tue, 28 Nov 2017 20:59:27 +0000 (28 12:59 -0800)
tree235e0a691c66aeb88f2616f4a810fa20dd89a86c
parente15f0caaeae5f8cd5f08ff41aa34ae18d4a9fdaa
install.sh: improve @basedir@ installation substitution

If $Girocco::Config::basedir has been set to "/var/tmp/repomgr"
then originally the following substitution was always made during
the install process:

    @basedir@  =>  "/var/tmp/repomgr"

This applies to all the processed files which consist of a combination
of shell and perl scripts.

In some situations that expansion was awkward as it always included
the double quotes.  As a result the expansion was changed to be a
bit smarter using a "lookbehind" (perl does the replacements) pattern
like so:

    (?<!")\@basedir\@  =>  "/var/tmp/repomgr"
    (?<=")\@basedir\@  =>  /var/tmp/repomgr

Notice how the surrounding double quotes are omitted if the "@basedir@"
is immediately preceded by a double-quote(") character.

Perl scripts, however, very much want to do this:

    use lib @basedir@;

But at the same time we want to be able to use "perl -c" on them and
maybe even run them in the unprocessed state.

However, since perl very much wants to first interpolate the
"@basedir" part and then complain about the "@;" part this does not
work out so well in practice.

We could change it to this instead:

    use lib "@basedir@";

That's slightly better except that now it still wants to interpolate
the "@basedir" part and then complain about it needing to be declared
in strict mode.  If strict mode is off we end up with effectively this:

    use lib "@";

along with a nasty warning.  But then copious compilation errors
ensue because the various following lines like this:

    use Girocco::Config;
    use Girocco::Util;
    # etc.

End up producing failures.  We could add yet more smarts to notice
a preceding single-quote(') as well as a double-quote and do this:

    use lib '@basedir@';

Besides the repugnance of having something inside single-quotes get
replaced, that means in order for even `perl -c` to work on the
script a suitable symbolic link under the name "@basedir@" needs
to be created in the current directory.

Surprisingly most operating systems find such a link to be perfectly
copacetic although the shell may need some ugly quoting to help it
out.  But POSIX does not allow such in the portable filename character
set [1].

Instead, add a new substitution for __BASEDIR__ that never includes
any surrounding quotes like so:

    __BASEDIR__  =>  /var/tmp/repomgr

This works better and leaves it up to the user whether or not to
add any kind of quotes.  It does, however, still get replaced inside
single-quotes which is still a bit repugnant, but that was previously
already the case anyway as single quotes are not being checked for.

Now, however, a perfectly portable symbolic link from "__BASEDIR__"
to "." can be created in the top-level directory allowing at least
`perl -c` to work on the scripts when used from the top-level
directory as long as they do something like this:

    use lib "__BASEDIR__";

In fact, in most cases, no symbolic link need be created at all provided
a "Girocco" directory (or link thereto) exists in the current directory.

Perl will just ignore the "__BASEDIR__" in its @INCDIRS list since it will
not exist and will then find the one in the current directory.

[1]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
install.sh