From e4d0d4dd28e95ca194c4cbab080114c265cba16f Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 26 Apr 2022 23:49:53 +0200 Subject: renamed script --- src/cron/gitjoe.pl | 104 -------------------------------------------- src/cron/stagit_generate.pl | 104 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 104 deletions(-) delete mode 100755 src/cron/gitjoe.pl create mode 100755 src/cron/stagit_generate.pl diff --git a/src/cron/gitjoe.pl b/src/cron/gitjoe.pl deleted file mode 100755 index a12528c..0000000 --- a/src/cron/gitjoe.pl +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/local/bin/perl - -use strict; -use warnings; -use Term::ANSIColor; -use File::Copy; - -use constant { - TMP_DIR => '/tmp/gitjoe/', - HOME_DIR => '/usr/local/git/', - SITE_DIR => '/usr/local/www/gitjoe/', -}; - -sub get_repos_index { - my $user = $_[0]; - my $home_dir = HOME_DIR . $user . '/'; - opendir(DIR, $home_dir); - my @repos; - my $i = 0; - while (my $dir = readdir(DIR)) { - next if ($dir =~ m/^\./); - next if (!(-e $home_dir . $dir . '/git-daemon-export-ok')); - $repos[$i] = $dir; - $i += 1; - } - closedir(DIR); - @repos = sort @repos; - return @repos; -} - -sub stagit_generate { - my ($user, @repos) = @_; - my $home_dir = HOME_DIR . $user . '/'; - chdir(TMP_DIR); - mkdir($user . '/', 0755); - my $i = 0; - my $repos_line = ""; - copy(SITE_DIR . 'css/gitjoe.css', './' . $user . '/style.css'); - copy(SITE_DIR . 'img/logo.png', './' . $user . '/logo.png'); - while ($i < @repos) { - chdir(TMP_DIR . $user . '/'); - $repos_line = $repos_line . ' ' . $home_dir . $repos[$i] . '/'; - substr($repos[$i], -4) = ""; - mkdir($repos[$i] . '/', 0755); - chdir(TMP_DIR . $user . '/' . $repos[$i] . '/'); - $repos[$i] = $repos[$i] . '.git'; - print "Indexing " . colored($user . '/' . $repos[$i], 'bold') . ".\n"; - system( - 'stagit', - $home_dir . $repos[$i] . '/' - ); - copy('../style.css', './style.css'); - copy('../logo.png', './logo.png'); - $i += 1; - } - chdir(TMP_DIR . $user . '/'); - system( - 'stagit-index ' . $repos_line . '>index.html' - ); - system( - "sed -i '' -e 's/" . $user . "<\\/td>/" . $user . "<\\/td>/g' index.html" - ); - system( - "sed -i '' -e 's/Repositories<\\/span><\\/td>/

" . $user . " - Repositories<\\/h1><\\/span><\\/td><\\/tr><\\/td>Back to GitJoe<\\/a><\\/td><\\/tr>/' index.html" - ); - system("sed -i '' -e 's/log.html/files.html/g' index.html"); - return; -} - -sub main { - my $home_dir = HOME_DIR; - my @users; - opendir(DIR, $home_dir); - my $i = 0; - while (my $dir = readdir(DIR)) { - next if ($dir eq 'git-ro'); - next if ($dir =~ m/^\./); - $users[$i] = $dir; - $i += 1; - } - closedir(DIR); - $i = 0; - mkdir(TMP_DIR, 0700); - while ($i < @users) { - my @repos = get_repos_index($users[$i]); - stagit_generate($users[$i], @repos); - system( - 'rm', - '-rf', - SITE_DIR . 'users/' . $users[$i] - ); - print "Removed user " . colored($users[$i], 'bold green') . " old directory from " . colored(SITE_DIR . 'users', 'bold') . ".\n"; - move(TMP_DIR . $users[$i], SITE_DIR . 'users/' . $users[$i]); - print "Moved user " . colored($users[$i], 'bold green') . " newly generated directory to " . colored(SITE_DIR . 'users', 'bold') . ".\n"; - $i += 1; - } - rmdir(TMP_DIR); - print "Updated GitJoe index.\n"; - exit; -} - -main(); - -__END__ diff --git a/src/cron/stagit_generate.pl b/src/cron/stagit_generate.pl new file mode 100755 index 0000000..a12528c --- /dev/null +++ b/src/cron/stagit_generate.pl @@ -0,0 +1,104 @@ +#!/usr/local/bin/perl + +use strict; +use warnings; +use Term::ANSIColor; +use File::Copy; + +use constant { + TMP_DIR => '/tmp/gitjoe/', + HOME_DIR => '/usr/local/git/', + SITE_DIR => '/usr/local/www/gitjoe/', +}; + +sub get_repos_index { + my $user = $_[0]; + my $home_dir = HOME_DIR . $user . '/'; + opendir(DIR, $home_dir); + my @repos; + my $i = 0; + while (my $dir = readdir(DIR)) { + next if ($dir =~ m/^\./); + next if (!(-e $home_dir . $dir . '/git-daemon-export-ok')); + $repos[$i] = $dir; + $i += 1; + } + closedir(DIR); + @repos = sort @repos; + return @repos; +} + +sub stagit_generate { + my ($user, @repos) = @_; + my $home_dir = HOME_DIR . $user . '/'; + chdir(TMP_DIR); + mkdir($user . '/', 0755); + my $i = 0; + my $repos_line = ""; + copy(SITE_DIR . 'css/gitjoe.css', './' . $user . '/style.css'); + copy(SITE_DIR . 'img/logo.png', './' . $user . '/logo.png'); + while ($i < @repos) { + chdir(TMP_DIR . $user . '/'); + $repos_line = $repos_line . ' ' . $home_dir . $repos[$i] . '/'; + substr($repos[$i], -4) = ""; + mkdir($repos[$i] . '/', 0755); + chdir(TMP_DIR . $user . '/' . $repos[$i] . '/'); + $repos[$i] = $repos[$i] . '.git'; + print "Indexing " . colored($user . '/' . $repos[$i], 'bold') . ".\n"; + system( + 'stagit', + $home_dir . $repos[$i] . '/' + ); + copy('../style.css', './style.css'); + copy('../logo.png', './logo.png'); + $i += 1; + } + chdir(TMP_DIR . $user . '/'); + system( + 'stagit-index ' . $repos_line . '>index.html' + ); + system( + "sed -i '' -e 's/" . $user . "<\\/td>/" . $user . "<\\/td>/g' index.html" + ); + system( + "sed -i '' -e 's/Repositories<\\/span><\\/td>/

" . $user . " - Repositories<\\/h1><\\/span><\\/td><\\/tr><\\/td>Back to GitJoe<\\/a><\\/td><\\/tr>/' index.html" + ); + system("sed -i '' -e 's/log.html/files.html/g' index.html"); + return; +} + +sub main { + my $home_dir = HOME_DIR; + my @users; + opendir(DIR, $home_dir); + my $i = 0; + while (my $dir = readdir(DIR)) { + next if ($dir eq 'git-ro'); + next if ($dir =~ m/^\./); + $users[$i] = $dir; + $i += 1; + } + closedir(DIR); + $i = 0; + mkdir(TMP_DIR, 0700); + while ($i < @users) { + my @repos = get_repos_index($users[$i]); + stagit_generate($users[$i], @repos); + system( + 'rm', + '-rf', + SITE_DIR . 'users/' . $users[$i] + ); + print "Removed user " . colored($users[$i], 'bold green') . " old directory from " . colored(SITE_DIR . 'users', 'bold') . ".\n"; + move(TMP_DIR . $users[$i], SITE_DIR . 'users/' . $users[$i]); + print "Moved user " . colored($users[$i], 'bold green') . " newly generated directory to " . colored(SITE_DIR . 'users', 'bold') . ".\n"; + $i += 1; + } + rmdir(TMP_DIR); + print "Updated GitJoe index.\n"; + exit; +} + +main(); + +__END__ -- cgit v1.2.3