prevent info leak when gitolite-shell is used as $SHELL...
[gitolite.git] / install
blob98d8aee9c34da419fb99b719904568a346725f51
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;
11 # meant to be run from the root of the gitolite tree, one level above 'src'
12 BEGIN { $ENV{GL_BINDIR} = $FindBin::RealBin . "/src"; }
13 BEGIN { $ENV{GL_LIBDIR} = "$ENV{GL_BINDIR}/lib"; }
14 use lib $ENV{GL_LIBDIR};
15 use Gitolite::Common;
17 =for usage
18 Usage (from gitolite clone directory):
20 ./install
21 to run gitolite using an absolute or relative path, for example
22 'src/gitolite' or '/full/path/to/this/dir/src/gitolite'
24 ./install -ln [<dir>]
25 to symlink just the gitolite executable to some <dir> that is in
26 $PATH. <dir> defaults to $HOME/bin if <dir> not specified. <dir> is
27 assumed to exist; gitolite will not create it.
29 Please provide a full path, not a relative path.
31 ./install -to <dir>
32 to copy the entire 'src' directory to <dir>. If <dir> is not in
33 $PATH, use the full path to run gitolite commands.
35 Please provide a full path, not a relative path.
37 Simplest use, if $HOME/bin exists and is in $PATH, is:
39 git clone git://github.com/sitaramc/gitolite
40 gitolite/install -ln
42 # now run setup
43 gitolite setup -pk /path/to/YourName.pub
44 =cut
46 my ( $to, $ln, $help, $quiet );
48 GetOptions(
49 'to=s' => \$to,
50 'ln:s' => \$ln,
51 'help|h' => \$help,
52 'quiet|q' => \$quiet,
54 usage() if $to and $ln or $help;
55 $ln = "$ENV{HOME}/bin" if defined($ln) and not $ln;
56 for my $d ($ln, $to) {
57 next unless $d; # ignore empty values
58 unless ( $d =~ m(^/) ) {
59 print STDERR "FATAL: please use an absolute path, not a relative path\n";
60 usage();
62 if ( not -d $d ) {
63 print STDERR "FATAL: '$d' does not exist.\n";
64 usage();
68 chdir($ENV{GL_BINDIR});
69 my $version = `git describe --tags --long --dirty=-dt 2>/dev/null`;
70 unless ($version =~ /^v\d/) {
71 print STDERR "git describe failed; cannot deduce version number\n";
72 $version = "(unknown)";
75 if ($to) {
76 _mkdir($to);
77 system("cp -RpP * $to");
78 _print( "$to/VERSION", $version );
79 } elsif ($ln) {
80 ln_sf( $ENV{GL_BINDIR}, "gitolite", $ln );
81 _print( "VERSION", $version );
82 } else {
83 say "use the following full path for gitolite:";
84 say "\t$ENV{GL_BINDIR}/gitolite";
85 _print( "VERSION", $version );