Git-Server
view release on metacpan or search on metacpan
}
if (!@found) {
# Try really hard to match, ignoring case and even ignoring non-wordspace
foreach my $agent_line (split /\n+/, $agentlist) {
(my $stripped = $agent_line) =~ s/[^\w\n]+//g;
push @found, $agent_line if $agent_line =~ /\Q$pick\E/i;
push @found, $agent_line if $agent_line =~ /$pick/i;
push @found, $agent_line if $clue and $agent_line =~ /\Q$clue\E/i;
push @found, $agent_line if $stripped =~ /\Q$pick/i;
push @found, $agent_line if $stripped =~ /$pick/i;
push @found, $agent_line if $clue and $stripped =~ /\Q$clue\E/i;
}
}
foreach my $m (@found) {
push @matches, $m if !$pushed->{$m}++;
}
}
foreach my $m (@matches) {
if (eval { require File::Temp;1 }) {
my $tmp = File::Temp->new( UNLINK => 0, SUFFIX => ".pub" );
print $tmp "$m\n";
close $tmp;
warn localtime().": [$$] $Script: --identity '$pub': Created temp pubkey file: $tmp: $m\n" if $ENV{DEBUG};
push @$files, $tmp;
}
}
return @$files;
}
if ($force_branch and @ARGV) {
warn "$0: Don't specify both --branch and commandline argument.\n";
sleep 1;
exec perldoc => $0 or die "$0: help menu unavailable\n";
}
$force_branch ||= shift;
# Expand relative [ -i <identity> ] paths before chdir
if (@$identities) {
foreach (@$identities) {
$_ = abs_path $1 if m{^([^/].*)} and -e $1 or !-e and m{(.+)\.pub$}m and -e $1;
$_ = abs_path "$_.pub" if !-e and -e "$_.pub";
}
}
# Handle [ -C <dir> ] first
if (@$chdir) {
chdir $_ or die "fatal: cannot change to '$_': $!\n" foreach @$chdir;
if (grep {/^[^\/]/} @$chdir) {
# Relative chdir may fail if re-invoked, so clear it from @invoked
for (my $i = 1; $i < @invoked; $i++) {
splice @invoked, --$i, ($2?1:2) if $invoked[$i-1] =~ /^(-C|--chdir)\b(=?).*$/;
}
}
$cwd = getcwd();
}
if (@$identities) {
# Sanity check to verify identity files are ready to go, and expand relative paths if needed.
my $verified_identities = [];
my $public_key_file = {};
my $private_key_file = {};
foreach my $ident (@$identities) {
if (my @found = agentkeys($ident)) {
foreach (@found) {
push @$verified_identities, $_ if !$public_key_file->{$_}++;
}
}
elsif (-e $ident && -r _ && -s _) {
my $pub = run_output_ignore_err "ssh-keygen", "-y", "-P", "", "-f", $ident;
if ($pub) {
warn localtime().": [$$] $Script: --identity '$ident': Using private key for: $pub";
push @$verified_identities, $ident if !$private_key_file->{$ident}++;
}
elsif ($ident =~ m{^(.+)\.pub$} and -r $1 and $ident = $1) {
redo; # Try again with the NON-".pub" file
}
else {
warn localtime().": [$$] $Script: --identity '$ident': Unable to read identity file. Passphrase required?\n";
}
}
else {
warn localtime().": [$$] $Script: --identity '$ident': Ignoring non-existent key\n";
}
}
$identities = $verified_identities;
}
$ENV{GIT_DIR} ||= abs_path(`git rev-parse --git-dir 2>/dev/null` =~ /^(.+)/ && $1 || ".git");
umask oct $1 if $umask and $umask =~ /^(\d+)$/;
$origin = current_origin();
$0 = "$Script - $cwd: Initial checkout [".checkout_branch()."]";
run_output_ignore_err "git", "checkout", checkout_branch;
sleep 1;
rebuild;
if (!$maxpatience) {
$0 = "$Script - $cwd: Searching for other deployers ...";
if (getps =~ /(.*\Q$Script - $cwd\E: Waiting.*)/) {
my $found = $1;
my $stagger = 5+int(rand()*115);
$0 = "$Script - $cwd: Waiting $stagger seconds for random stagger ...";
warn localtime().": [$$] $Script: Since no --max-delay option was provided, waiting $stagger seconds random stagger delay before taking over for other deployer:\n$found\n";
print run_output_include_err(sleep => $stagger);
}
}
if (sleep 1) {
# Run quick pre-flight sanity test before entering loop
local $maxpatience = 1;
my $update = pull_push_notification;
$0 = "$Script - $cwd: Scanning updates";
die localtime().": [$$] $Script: Fatal crash while attempting to pull from ".run_output_ignore_err("git","config","remote.$origin.url")."\n$update\n\n".localtime().": [$$] $Script: Manual intervention required.\n" if $update =~ /^fatal:/m;
}
background if $background;
sleep 1;
while (1) {
my $update = pull_push_notification;
$deploying_version ||= $update =~ / git-server(?: v([\d.]+):)?.*waiting for notification/ ? $1 || "OLD" : 0 or
$maxpatience or $maxdelayrecommended ||= warn localtime().": [$$] $Script: Warning: Missing recommended [ --max-delay <INTERVAL_SECONDS> ] for NON-deploy repo: ".run_output_ignore_err("git","config","remote.$origin.url");
my $branch = checkout_branch;
$update .= run_output_include_err "git", "checkout", $branch;
$update .= run_output_include_err "git", "rebase", "$origin/$branch";
$0 = "$Script - $cwd: Scanning updates";
$update .= run_output_include_err "git", "rebase", "--abort" if $update =~ /fix conflicts|git rebase.*--continue|you need to resolve your|stop rebasing/;
if (-M "$Bin/$Script" < 0) {
# Myself update detected so need to respawn
warn localtime().": [$$] $Script: Auto-update $Script respawning ...\n";
( run in 2.389 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )