minor fixup to a test script...
[gitolite.git] / install
blobfa6fc26c18ccb7cd730d4d274cf066e3120cc3ba
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 # Clearly you don't need a program to make one measly symlink, but the git
6 # describe command involved in generating the VERSION string is a bit fiddly.
8 use Getopt::Long;
9 use FindBin;
10 use Config;
12 # meant to be run from the root of the gitolite tree, one level above 'src'
13 BEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin . "/src"; }
14 BEGIN { $ENV{GL_LIBDIR} = "$ENV{GL_BINDIR}/lib"; }
15 use lib $ENV{GL_LIBDIR};
16 use Gitolite::Common;
18 =for usage
19 Usage (from gitolite clone directory):
21 ./install
22 to run gitolite using an absolute or relative path, for example
23 'src/gitolite' or '/full/path/to/this/dir/src/gitolite'
25 ./install -ln [<dir>]
26 to symlink just the gitolite executable to some <dir> that is in
27 $PATH. <dir> defaults to $HOME/bin if <dir> not specified. <dir> is
28 assumed to exist; gitolite will not create it.
30 Please provide a full path, not a relative path.
32 ./install -to <dir>
33 to copy the entire 'src' directory to <dir>. If <dir> is not in
34 $PATH, use the full path to run gitolite commands.
36 Please provide a full path, not a relative path.
38 <perl-executable> ./install -to <dir>
39 to copy the entire 'src' directory to <dir>, but will replace
40 all of the shebangs with the path to <perl-executable>. This
41 is a way to force gitolite to use some perl that is not
42 installed at /usr/bin/perl.
44 Simplest use, if $HOME/bin exists and is in $PATH, is:
46 git clone https://github.com/sitaramc/gitolite
47 gitolite/install -ln
49 # now run setup
50 gitolite setup -pk /path/to/YourName.pub
51 =cut
53 my ( $to, $ln, $help, $quiet );
55 GetOptions(
56 'to=s' => \$to,
57 'ln:s' => \$ln,
58 'help|h' => \$help,
59 'quiet|q' => \$quiet,
61 usage() if $to and $ln or $help;
62 $ln = "$ENV{HOME}/bin" if defined($ln) and not $ln;
63 for my $d ($ln, $to) {
64 next unless $d; # ignore empty values
65 unless ( $d =~ m(^/) ) {
66 print STDERR "FATAL: please use an absolute path, not a relative path\n";
67 usage();
69 if ( not -d $d ) {
70 print STDERR "FATAL: '$d' does not exist.\n";
71 usage();
75 chdir($ENV{GL_BINDIR});
76 my $version = `git describe --tags --long --dirty=-dt 2>/dev/null`;
77 unless ($version =~ /^v\d/) {
78 print STDERR "git describe failed; cannot deduce version number\n";
79 $version = "(unknown)";
82 if ($to) {
83 _mkdir($to);
84 system("cp -RpP * $to");
85 _print( "$to/VERSION", $version );
87 # Replace shebangs if necessary.
88 my $thisperl = $Config{perlpath};
89 if ($thisperl ne '/usr/bin/perl') {
90 system("cd $to; grep -r -l /usr/bin/perl | xargs perl -pi -e 's(^#!/usr/bin/perl)(#!$thisperl)'");
92 } elsif ($ln) {
93 ln_sf( $ENV{GL_BINDIR}, "gitolite", $ln );
94 _print( "VERSION", $version );
95 } else {
96 say "use the following full path for gitolite:";
97 say "\t$ENV{GL_BINDIR}/gitolite";
98 _print( "VERSION", $version );