2012-03-09 12:49:29 +01:00
|
|
|
package Gitolite::Setup;
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
# implements 'gitolite setup'
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
2012-03-12 16:24:30 +01:00
|
|
|
=for args
|
2012-03-15 13:46:16 +01:00
|
|
|
Usage: gitolite setup [<option>]
|
2012-03-08 09:00:13 +01:00
|
|
|
|
2012-03-15 13:46:16 +01:00
|
|
|
-pk, --pubkey <file> pubkey file name
|
2012-03-08 09:00:13 +01:00
|
|
|
|
2012-03-15 13:46:16 +01:00
|
|
|
Setup gitolite, compile conf, and fixup hooks. The pubkey is required on the
|
|
|
|
first run.
|
2012-03-08 09:00:13 +01:00
|
|
|
=cut
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
@EXPORT = qw(
|
|
|
|
setup
|
|
|
|
);
|
|
|
|
|
|
|
|
use Exporter 'import';
|
|
|
|
use Getopt::Long;
|
|
|
|
|
|
|
|
use Gitolite::Rc;
|
|
|
|
use Gitolite::Common;
|
|
|
|
use Gitolite::Conf::Store;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
sub setup {
|
|
|
|
my ( $admin, $pubkey, $argv ) = args();
|
2012-03-15 13:46:16 +01:00
|
|
|
setup_glrc();
|
|
|
|
setup_gladmin( $admin, $pubkey, $argv );
|
2012-03-08 09:00:13 +01:00
|
|
|
|
2012-03-10 14:26:29 +01:00
|
|
|
_system("$ENV{GL_BINDIR}/gitolite compile");
|
2012-03-19 03:01:09 +01:00
|
|
|
_system("$ENV{GL_BINDIR}/gitolite trigger POST_COMPILE");
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
hook_repos(); # all of them, just to be sure
|
|
|
|
}
|
|
|
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
sub args {
|
|
|
|
my $admin = '';
|
|
|
|
my $pubkey = '';
|
|
|
|
my $help = 0;
|
|
|
|
my $argv = join( " ", @ARGV );
|
|
|
|
|
|
|
|
GetOptions(
|
2012-03-15 15:34:30 +01:00
|
|
|
'admin|a=s' => \$admin,
|
|
|
|
'pubkey|pk=s' => \$pubkey,
|
|
|
|
'help|h' => \$help,
|
2012-03-08 09:00:13 +01:00
|
|
|
) or usage();
|
|
|
|
|
2012-03-15 13:46:16 +01:00
|
|
|
usage() if $help or ($pubkey and $admin);
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
if ($pubkey) {
|
|
|
|
$pubkey =~ /\.pub$/ or _die "$pubkey name does not end in .pub";
|
2012-03-15 13:46:16 +01:00
|
|
|
$pubkey =~ /\@/ and _die "$pubkey name contains '\@'";
|
2012-03-08 09:00:13 +01:00
|
|
|
tsh_try("cat $pubkey") or _die "$pubkey not a readable file";
|
|
|
|
tsh_lines() == 1 or _die "$pubkey must have exactly one line";
|
|
|
|
tsh_try("ssh-keygen -l -f $pubkey") or _die "$pubkey does not seem to be a valid ssh pubkey file";
|
2012-03-15 13:46:16 +01:00
|
|
|
|
|
|
|
$admin = $pubkey;
|
|
|
|
$admin =~ s(.*/)();
|
|
|
|
$admin =~ s/\.pub$//;
|
2012-03-08 09:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ( $admin || '', $pubkey || '', $argv );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setup_glrc {
|
2012-03-15 13:46:16 +01:00
|
|
|
_print( glrc('default-filename'), glrc('default-text') ) if not glrc('filename');
|
2012-03-08 09:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub setup_gladmin {
|
|
|
|
my ( $admin, $pubkey, $argv ) = @_;
|
2012-03-15 13:46:16 +01:00
|
|
|
_die "no existing conf file found, '-a' required"
|
2012-03-15 15:34:30 +01:00
|
|
|
if not $admin and not -f "$rc{GL_ADMIN_BASE}/conf/gitolite.conf";
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
# reminder: 'admin files' are in ~/.gitolite, 'admin repo' is
|
2012-03-16 05:29:45 +01:00
|
|
|
# $rc{GL_REPO_BASE}/gitolite-admin.git
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
# grab the pubkey content before we chdir() away
|
|
|
|
my $pubkey_content = '';
|
2012-03-15 13:46:16 +01:00
|
|
|
$pubkey_content = slurp($pubkey) if $pubkey;
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
# set up the admin files in admin-base
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
_mkdir( $rc{GL_ADMIN_BASE} );
|
|
|
|
_chdir( $rc{GL_ADMIN_BASE} );
|
2012-03-08 09:00:13 +01:00
|
|
|
|
2012-03-15 14:44:40 +01:00
|
|
|
tsh_try("cd \$GL_BINDIR; git describe --tags --long --dirty=-dt 2>/dev/null")
|
2012-03-15 15:34:30 +01:00
|
|
|
and _print( "VERSION", tsh_text() );
|
2012-03-15 14:44:40 +01:00
|
|
|
|
2012-03-08 09:00:13 +01:00
|
|
|
_mkdir("conf");
|
2012-03-17 16:43:28 +01:00
|
|
|
_mkdir("logs");
|
2012-03-08 09:00:13 +01:00
|
|
|
my $conf;
|
|
|
|
{
|
|
|
|
local $/ = undef;
|
|
|
|
$conf = <DATA>;
|
|
|
|
}
|
|
|
|
$conf =~ s/%ADMIN/$admin/g;
|
|
|
|
|
2012-03-15 13:46:16 +01:00
|
|
|
_print( "conf/gitolite.conf", $conf ) if not -f "conf/gitolite.conf";
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
if ($pubkey) {
|
|
|
|
_mkdir("keydir");
|
2012-03-15 13:46:16 +01:00
|
|
|
_print( "keydir/$admin.pub", $pubkey_content );
|
2012-03-08 09:00:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# set up the admin repo in repo-base
|
|
|
|
|
|
|
|
_chdir();
|
2012-03-16 05:29:45 +01:00
|
|
|
_mkdir( $rc{GL_REPO_BASE} );
|
|
|
|
_chdir( $rc{GL_REPO_BASE} );
|
2012-03-08 09:00:13 +01:00
|
|
|
|
2012-03-15 13:46:16 +01:00
|
|
|
new_repo("gitolite-admin") if not -d "gitolite-admin.git";
|
2012-03-08 09:00:13 +01:00
|
|
|
|
|
|
|
# commit the admin files to the admin repo
|
|
|
|
|
2012-03-16 05:29:45 +01:00
|
|
|
$ENV{GIT_WORK_TREE} = $rc{GL_ADMIN_BASE};
|
|
|
|
_chdir("$rc{GL_REPO_BASE}/gitolite-admin.git");
|
2012-03-10 14:26:29 +01:00
|
|
|
_system("git add conf/gitolite.conf");
|
|
|
|
_system("git add keydir") if $pubkey;
|
2012-03-08 09:00:13 +01:00
|
|
|
tsh_try("git config --get user.email") or tsh_run( "git config user.email $ENV{USER}\@" . `hostname` );
|
|
|
|
tsh_try("git config --get user.name") or tsh_run( "git config user.name '$ENV{USER} on '" . `hostname` );
|
|
|
|
tsh_try("git diff --cached --quiet")
|
|
|
|
or tsh_try("git commit -am 'gl-setup $argv'")
|
|
|
|
or die "setup failed to commit to the admin repo";
|
|
|
|
delete $ENV{GIT_WORK_TREE};
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
repo gitolite-admin
|
|
|
|
RW+ = %ADMIN
|
|
|
|
|
|
|
|
repo testing
|
|
|
|
RW+ = @all
|