| 
					
				 | 
			
			
				@@ -1,138 +0,0 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-#!/usr/bin/perl 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-############################# 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# DEPRECATED - USED GSG NOW # 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-############################# 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use strict; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-use warnings; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my $top_level_dir = "/var/www/html/git/"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my $projects_dir = $top_level_dir . "projects/"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my $index = $top_level_dir . "index.html"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my @ignore_dirs = ( "finance-perl.git/","misc-scripts.git/","git-site-gen.git/" ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my @git_project_dirs; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-foreach my $dir ( split("\n",`ls -d */`) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	chomp $dir; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if ( grep( /^$dir$/, @ignore_dirs ) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		print "Skipping $dir\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		next; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if ( $dir =~ /.git\/$/ ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		push(@git_project_dirs,$dir); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my $write = sub { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $content = shift; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $path = shift; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	open(my $fh, ">", $path) or die "Couldnt open $path\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	print $fh "$content"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	close $fh; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-my $append = sub { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $content = shift; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $path = shift; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	open(my $fh, ">>", $path) or die "Couldnt open $path\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	print $fh "$content"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	close $fh; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-$write->("",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-foreach my $dir ( split("\n", `cd $projects_dir ; ls -d */; cd /home/git`) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	if ( ! grep( /^$dir$/, @git_project_dirs ) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		print "Found $dir in webroot but not in git root, removing...\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		my $rmdir = $projects_dir . $dir; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		print "Removing $rmdir\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		system("rm -rf $rmdir") == 0 or die "Couldnt rm $dir\n"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# Write index 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-$append->("<html><body><b>Git Projects</b><br><head><META NAME=\"ROBOTS\" CONTENT=\"NOINDEX, NOFOLLOW\"></head>\n",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-$append->("<small><i>Statically generated web root for browsing my git projects</i></small><br>",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-$append->("<small><i>This is a read-only site and does not provide a merge/clone interface</i></small><hr/>",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-foreach my $project ( @git_project_dirs ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<table><div id=\"cotent\"><table id=\"index\"><tbody>",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<tr><td><a href=\"projects/$project/index.html\">$project</a></td>",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	#$append->("<a href=\"projects/$project/index.html\">$project</a><br>",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	system("mkdir -p $projects_dir$project") == 0 or die "Couldnt create $projects_dir/$project"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-$append->("</tr></tbody></table></div></body></html>",$index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# Write files 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-foreach my $project ( @git_project_dirs ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $spec_project_dir = $projects_dir . $project . "/"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $project_index = $spec_project_dir . "/index.html"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$write->("",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<html><a href=\"../../../index.html\">Return to index</a></b><hr/>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<b>Files for $project</b><br>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<hr/>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my %fileTree; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	foreach my $file ( split("\n", `cd $project ; git ls-tree --full-tree -r HEAD; cd ..`) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		chomp $file; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$file =~ /([a-z0-9]{40})\t(.*)$/; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		# Name - commit hash 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$fileTree{$2} = $1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my %fileContent; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	foreach my $filename ( keys %fileTree ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		my $content = `cd $project ; git show $fileTree{$filename} ; cd ..`; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		chomp $content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$fileContent{$filename} = $content; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<table><div id=\"cotent\"><table id=\"index\"><thead><tr><td><b>File</b></td><td><b>Commit</b></td></tr></thead><tbody>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	foreach my $filename ( sort keys %fileContent ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		my $browserVersion = $filename . ".txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if ( $filename =~ m/\// ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			my $copy = $filename; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			$copy =~ s/\//_/g; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			$browserVersion = $copy . ".txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		#$append->("$fileTree{$filename} - <a href=\"$browserVersion\">$filename</a><br>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$append->("<tr><td><a href=\"$browserVersion\">$filename</a></td><td>$fileTree{$filename}</td>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$write->("$fileContent{$filename}",$spec_project_dir . $browserVersion); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("</tr></tbody></table></div></body>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<br>", $project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-# Get logs hash and write out logs page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-foreach my $project ( @git_project_dirs ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $spec_project_dir = $projects_dir . $project . "/"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my $project_index = $spec_project_dir . "/index.html"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my @commit_ids; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	foreach my $log_line ( split("\n",`cd $project; git log ; cd ..`) ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		if ( $log_line =~ m/commit\ ([a-z0-9]{40})/ ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-			push(@commit_ids,$1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# Key: commit SHA, value commit info (git show) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	my %commits; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	foreach my $commit_id ( @commit_ids ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		my $commit_info = `cd $project; git show $commit_id; cd ..`; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		chomp $commit_info; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$commits{$commit_id} = $commit_info; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<html><b>Logs for $project</b><br>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<table><div id=\"cotent\"><table id=\"index\"><tbody>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("<hr/>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	# iterate over array to keep ordering 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	foreach my $commit_id ( @commit_ids ) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		my $filename = $commit_id . ".txt"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		#$append->("<a href=\"$filename\">$commit_id</a><br>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$append->("<tr><td><a href=\"$filename\">$filename</a></td>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		$write->($commits{$commit_id},$spec_project_dir . $filename);	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("</tr></tbody></table></div></body>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	$append->("</html>",$project_index); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-print "Done\n"; 
			 |