2009-08-30 08:41:55 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2009-10-13 06:32:45 +02:00
|
|
|
our ($REPO_BASE, $GL_ADMINDIR, $GL_CONF, $GIT_PATH);
|
2009-08-30 08:41:55 +02:00
|
|
|
|
2009-10-25 13:03:06 +01:00
|
|
|
# setup quiet mode if asked; please do not use this when running manually
|
|
|
|
open STDOUT, ">", "/dev/null" if (@ARGV and shift eq '-q');
|
|
|
|
|
2009-08-30 08:41:55 +02:00
|
|
|
# wrapper around mkdir; it's not an error if the directory exists, but it is
|
|
|
|
# an error if it doesn't exist and we can't create it
|
|
|
|
sub wrap_mkdir
|
|
|
|
{
|
|
|
|
my $dir = shift;
|
2009-09-10 15:35:07 +02:00
|
|
|
if ( -d $dir ) {
|
2009-10-25 13:03:06 +01:00
|
|
|
print "$dir already exists\n";
|
2009-09-10 15:35:07 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mkdir($dir) or die "mkdir $dir failed: $!\n";
|
2009-10-25 13:03:06 +01:00
|
|
|
print "created $dir\n";
|
2009-08-30 08:41:55 +02:00
|
|
|
}
|
|
|
|
|
2009-10-25 03:59:52 +01:00
|
|
|
# the common setup module is in the same directory as this running program is
|
|
|
|
my $bindir = $0;
|
|
|
|
$bindir =~ s/\/[^\/]+$//;
|
|
|
|
require "$bindir/gitolite.pm";
|
|
|
|
|
|
|
|
# ask where the rc file is, get it, and "do" it
|
|
|
|
&where_is_rc();
|
|
|
|
unless ($ENV{GL_RC}) {
|
2009-08-30 08:41:55 +02:00
|
|
|
# doesn't exist. Copy it across, tell user to edit it and come back
|
2009-10-25 03:59:52 +01:00
|
|
|
my $glrc = $ENV{HOME} . "/.gitolite.rc";
|
2009-08-30 08:41:55 +02:00
|
|
|
system("cp conf/example.gitolite.rc $glrc");
|
2009-10-25 13:03:06 +01:00
|
|
|
print "created $glrc\n";
|
|
|
|
print "please edit it, change the paths if you wish to, and RERUN THIS SCRIPT\n";
|
2009-08-30 08:41:55 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2009-10-25 03:59:52 +01:00
|
|
|
# ok now the rc file exists; read it to get the other paths
|
|
|
|
die "parse $ENV{GL_RC} failed: " . ($! or $@) unless do $ENV{GL_RC};
|
2009-08-30 08:41:55 +02:00
|
|
|
|
2009-10-13 06:32:45 +02:00
|
|
|
# add a custom path for git binaries, if specified
|
|
|
|
$ENV{PATH} .= ":$GIT_PATH" if $GIT_PATH;
|
|
|
|
|
2009-08-30 08:41:55 +02:00
|
|
|
# mkdir $REPO_BASE, $GL_ADMINDIR if they don't already exist
|
2009-09-06 10:04:41 +02:00
|
|
|
my $repo_base_abs = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
|
|
|
|
wrap_mkdir($repo_base_abs);
|
2009-08-30 08:41:55 +02:00
|
|
|
wrap_mkdir($GL_ADMINDIR);
|
|
|
|
# mkdir $GL_ADMINDIR's subdirs
|
2009-09-06 10:04:41 +02:00
|
|
|
for my $dir qw(conf doc keydir logs src) {
|
2009-08-30 08:41:55 +02:00
|
|
|
wrap_mkdir("$GL_ADMINDIR/$dir");
|
|
|
|
}
|
|
|
|
|
|
|
|
# "src" and "doc" will be overwritten on each install, but not conf
|
|
|
|
system("cp -R src doc $GL_ADMINDIR");
|
|
|
|
|
|
|
|
unless (-f $GL_CONF) {
|
2009-10-25 13:03:06 +01:00
|
|
|
print <<EOF;
|
2010-02-08 12:08:28 +01:00
|
|
|
please do the following:
|
|
|
|
1. create and edit $GL_CONF to contain something like this:
|
|
|
|
repo gitolite-admin
|
|
|
|
RW+ = yourname
|
|
|
|
2. copy "yourname.pub" to $GL_ADMINDIR/keydir
|
|
|
|
3. run this command
|
|
|
|
$GL_ADMINDIR/src/gl-compile-conf
|
2009-08-30 08:41:55 +02:00
|
|
|
EOF
|
|
|
|
}
|
2009-09-01 17:03:19 +02:00
|
|
|
|
2009-11-13 00:33:09 +01:00
|
|
|
# finally, hooks must be propagated to all the repos in case they changed
|
2009-09-06 10:04:41 +02:00
|
|
|
chdir("$repo_base_abs") or die "chdir $repo_base_abs failed: $!\n";
|
|
|
|
for my $repo (`find . -type d -name "*.git"`) {
|
|
|
|
chomp ($repo);
|
2009-11-13 00:33:09 +01:00
|
|
|
# propagate our own, plus any local admin-defined, hooks
|
2010-02-05 02:19:07 +01:00
|
|
|
ln_sf("$GL_ADMINDIR/src/hooks", "*", "$repo/hooks");
|
2009-09-06 10:04:41 +02:00
|
|
|
chmod 0755, "$repo/hooks/update";
|
2009-09-01 17:03:19 +02:00
|
|
|
}
|
2009-10-05 12:38:10 +02:00
|
|
|
|
|
|
|
# oh and one of those repos is a bit more special and has an extra hook :)
|
2009-10-10 09:22:40 +02:00
|
|
|
if ( -d "gitolite-admin.git/hooks" ) {
|
2009-10-25 13:03:06 +01:00
|
|
|
print "copying post-update hook to gitolite-admin repo...\n";
|
2010-02-05 02:19:07 +01:00
|
|
|
unlink "gitolite-admin.git/hooks/post-update";
|
|
|
|
symlink "$GL_ADMINDIR/src/ga-post-update-hook", "gitolite-admin.git/hooks/post-update"
|
|
|
|
or die "could not symlink post-update hook\n";
|
2009-10-10 09:22:40 +02:00
|
|
|
chmod 0755, "gitolite-admin.git/hooks/post-update";
|
|
|
|
}
|
2009-11-13 00:33:09 +01:00
|
|
|
|
|
|
|
# fixup program renames
|
|
|
|
for my $oldname qw(pta-hook.sh conf-convert.pl 00-easy-install.sh 99-emergency-addkey.sh install.pl update-hook.pl) {
|
|
|
|
unlink "$GL_ADMINDIR/src/$oldname";
|
|
|
|
unlink "$ENV{HOME}/gitolite-install/src/$oldname";
|
|
|
|
}
|