2009-08-30 12:11:55 +05:30
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2010-04-26 21:55:02 +05:30
|
|
|
# INTERNAL COMMAND. NOT MEANT TO BE RUN BY THE USER DIRECTLY.
|
|
|
|
|
2009-08-30 12:11:55 +05:30
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2010-08-17 21:35:54 +05:30
|
|
|
our ($REPO_BASE, $GL_ADMINDIR, $GL_CONF, $GIT_PATH, $GL_PACKAGE_CONF, $GL_PACKAGE_HOOKS, $GL_PERFLOGT);
|
2009-08-30 12:11:55 +05:30
|
|
|
|
2009-10-25 17:33:06 +05:30
|
|
|
# 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 12:11:55 +05:30
|
|
|
# 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 19:05:07 +05:30
|
|
|
if ( -d $dir ) {
|
2009-10-25 17:33:06 +05:30
|
|
|
print "$dir already exists\n";
|
2009-09-10 19:05:07 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
mkdir($dir) or die "mkdir $dir failed: $!\n";
|
2009-10-25 17:33:06 +05:30
|
|
|
print "created $dir\n";
|
2009-08-30 12:11:55 +05:30
|
|
|
}
|
|
|
|
|
2009-10-25 08:29:52 +05:30
|
|
|
# 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 12:11:55 +05:30
|
|
|
# doesn't exist. Copy it across, tell user to edit it and come back
|
2009-10-25 08:29:52 +05:30
|
|
|
my $glrc = $ENV{HOME} . "/.gitolite.rc";
|
2010-02-10 10:29:49 +05:30
|
|
|
if ($GL_PACKAGE_CONF) {
|
|
|
|
system("cp $GL_PACKAGE_CONF/example.gitolite.rc $glrc");
|
|
|
|
} else {
|
|
|
|
system("cp $bindir/../conf/example.gitolite.rc $glrc");
|
|
|
|
}
|
2009-10-25 17:33:06 +05:30
|
|
|
print "created $glrc\n";
|
|
|
|
print "please edit it, change the paths if you wish to, and RERUN THIS SCRIPT\n";
|
2009-08-30 12:11:55 +05:30
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2009-10-25 08:29:52 +05:30
|
|
|
# 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 12:11:55 +05:30
|
|
|
|
2009-10-13 10:02:45 +05:30
|
|
|
# add a custom path for git binaries, if specified
|
|
|
|
$ENV{PATH} .= ":$GIT_PATH" if $GIT_PATH;
|
|
|
|
|
2009-08-30 12:11:55 +05:30
|
|
|
# mkdir $REPO_BASE, $GL_ADMINDIR if they don't already exist
|
2010-06-29 10:55:36 +05:30
|
|
|
$ENV{GL_REPO_BASE_ABS} = ( $REPO_BASE =~ m(^/) ? $REPO_BASE : "$ENV{HOME}/$REPO_BASE" );
|
|
|
|
wrap_mkdir($ENV{GL_REPO_BASE_ABS});
|
2009-08-30 12:11:55 +05:30
|
|
|
wrap_mkdir($GL_ADMINDIR);
|
|
|
|
# mkdir $GL_ADMINDIR's subdirs
|
2010-02-09 19:37:37 +05:30
|
|
|
for my $dir qw(conf doc keydir logs src hooks hooks/common hooks/gitolite-admin) {
|
2010-02-10 10:29:49 +05:30
|
|
|
# some of them will stay empty; too lazy to fix right now ;-)
|
2009-08-30 12:11:55 +05:30
|
|
|
wrap_mkdir("$GL_ADMINDIR/$dir");
|
|
|
|
}
|
|
|
|
|
|
|
|
# "src" and "doc" will be overwritten on each install, but not conf
|
2010-02-10 10:29:49 +05:30
|
|
|
if ($GL_PACKAGE_HOOKS) {
|
2010-03-14 22:07:34 +05:30
|
|
|
system("cp -R -p $GL_PACKAGE_HOOKS $GL_ADMINDIR");
|
2010-02-10 10:29:49 +05:30
|
|
|
} else {
|
2010-03-14 22:07:34 +05:30
|
|
|
system("cp -R -p $bindir/../src $bindir/../doc $bindir/../hooks $GL_ADMINDIR");
|
|
|
|
system("cp $bindir/../conf/VERSION $GL_ADMINDIR/conf");
|
2010-02-10 10:29:49 +05:30
|
|
|
}
|
2009-08-30 12:11:55 +05:30
|
|
|
|
2010-02-10 10:29:49 +05:30
|
|
|
unless (-f $GL_CONF or $GL_PACKAGE_CONF) {
|
2009-10-25 17:33:06 +05:30
|
|
|
print <<EOF;
|
2010-02-08 16:38:28 +05:30
|
|
|
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 12:11:55 +05:30
|
|
|
EOF
|
|
|
|
}
|
2009-09-01 20:33:19 +05:30
|
|
|
|
2009-11-13 05:03:09 +05:30
|
|
|
# finally, hooks must be propagated to all the repos in case they changed
|
2010-06-29 10:55:36 +05:30
|
|
|
chdir("$ENV{GL_REPO_BASE_ABS}") or die "chdir $ENV{GL_REPO_BASE_ABS} failed: $!\n";
|
2009-09-06 13:34:41 +05:30
|
|
|
for my $repo (`find . -type d -name "*.git"`) {
|
|
|
|
chomp ($repo);
|
2009-11-13 05:03:09 +05:30
|
|
|
# propagate our own, plus any local admin-defined, hooks
|
2010-02-09 19:37:37 +05:30
|
|
|
ln_sf("$GL_ADMINDIR/hooks/common", "*", "$repo/hooks");
|
2010-02-10 16:19:20 +05:30
|
|
|
# in case of package install, GL_ADMINDIR is no longer the top cop;
|
|
|
|
# override with the package hooks
|
|
|
|
ln_sf("$GL_PACKAGE_HOOKS/common", "*", "$repo/hooks") if $GL_PACKAGE_HOOKS;
|
2009-09-06 13:34:41 +05:30
|
|
|
chmod 0755, "$repo/hooks/update";
|
2009-09-01 20:33:19 +05:30
|
|
|
}
|
2009-10-05 16:08:10 +05:30
|
|
|
|
|
|
|
# oh and one of those repos is a bit more special and has an extra hook :)
|
2009-10-10 12:52:40 +05:30
|
|
|
if ( -d "gitolite-admin.git/hooks" ) {
|
2009-10-25 17:33:06 +05:30
|
|
|
print "copying post-update hook to gitolite-admin repo...\n";
|
2010-02-05 06:49:07 +05:30
|
|
|
unlink "gitolite-admin.git/hooks/post-update";
|
2010-02-09 19:37:37 +05:30
|
|
|
symlink "$GL_ADMINDIR/hooks/gitolite-admin/post-update", "gitolite-admin.git/hooks/post-update"
|
2010-02-05 06:49:07 +05:30
|
|
|
or die "could not symlink post-update hook\n";
|
2010-02-10 16:19:20 +05:30
|
|
|
# ditto... (see previous block)
|
|
|
|
ln_sf("$GL_PACKAGE_HOOKS/gitolite-admin", "post-update", "gitolite-admin.git/hooks") if $GL_PACKAGE_HOOKS;
|
2009-10-10 12:52:40 +05:30
|
|
|
chmod 0755, "gitolite-admin.git/hooks/post-update";
|
|
|
|
}
|
2009-11-13 05:03:09 +05:30
|
|
|
|
|
|
|
# fixup program renames
|
2010-07-25 03:23:59 +05:30
|
|
|
for my $oldname qw(pta-hook.sh conf-convert.pl 00-easy-install.sh 99-emergency-addkey.sh gl-emergency-addkey install.pl update-hook.pl hooks/update ga-post-update-hook VERSION) {
|
2009-11-13 05:03:09 +05:30
|
|
|
unlink "$GL_ADMINDIR/src/$oldname";
|
|
|
|
unlink "$ENV{HOME}/gitolite-install/src/$oldname";
|
|
|
|
}
|