aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/update/gitjoe.pl35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/update/gitjoe.pl b/src/update/gitjoe.pl
index 86d1df3..6ae1930 100755
--- a/src/update/gitjoe.pl
+++ b/src/update/gitjoe.pl
@@ -4,6 +4,11 @@ use strict;
use warnings;
use Term::ANSIColor;
use File::Copy;
+use Capture::Tiny;
+use constant {
+ TMP_DIR => '/tmp/gitjoe',
+ SITE_DIR => '/usr/local/www/gitjoe/'
+};
sub get_repos_index {
my $user = $_[0];
@@ -24,25 +29,19 @@ sub get_repos_index {
sub stagit_generate {
my ($user, @repos) = @_;
- my $site_dir = '/usr/local/www/gitjoe/';
my $home_dir = '/usr/home/' . $user . '/';
- chdir($site_dir);
- system(
- '/bin/rm',
- '-rf',
- $user . '/'
- );
+ chdir(TMP_DIR);
mkdir($user . '/', 0755);
my $i = 0;
my $repos_line = "";
- copy('./css/gitjoe.css', './' . $user . '/style.css');
- copy('./img/logo.png', './' . $user . '/logo.png');
+ copy(SITE_DIR . 'css/gitjoe.css', './' . $user . '/style.css');
+ copy(SITE_DIR . 'img/logo.png', './' . $user . '/logo.png');
while ($i < @repos) {
- chdir($site_dir . $user . '/');
+ chdir(TMP_DIR . $user . '/');
$repos_line = $repos_line . ' ' . $home_dir . $repos[$i] . '/';
substr($repos[$i], -4) = "";
mkdir($repos[$i] . '/', 0755);
- chdir($site_dir . $user . '/' . $repos[$i] . '/');
+ chdir(TMP_DIR . $user . '/' . $repos[$i] . '/');
$repos[$i] = $repos[$i] . '.git';
print "Indexing " . colored($user . '/' . $repos[$i], 'bold') . ".\n";
system(
@@ -53,7 +52,7 @@ sub stagit_generate {
copy('../logo.png', './logo.png');
$i += 1;
}
- chdir($site_dir . $user . '/');
+ chdir(TMP_DIR . $user . '/');
system(
'/usr/local/bin/dash',
'-c',
@@ -62,20 +61,18 @@ sub stagit_generate {
system(
'/usr/local/bin/dash',
'-c',
- "/usr/bin/sed 's/<td>" . $user . "<\\/td>/<td class=\"td_author\">" . $user . "<\\/td>/g' index.html >sedded_index.html"
+ "/usr/local/bin/gsed -i 's/<td>" . $user . "<\\/td>/<td class=\"td_author\">" . $user . "<\\/td>/g' index.html"
);
system(
'/usr/local/bin/dash',
'-c',
- "/usr/bin/sed 's/<td><span class=\"desc\">Repositories<\\/span><\\/td>/<td><span class=\"desc\"><h1>" . $user . " - Repositories<\\/h1><\\/span><\\/td><\\/tr><tr><td><\\/td><td>Back to <a href=\"https:\\/\\/git.jozanleclerc.xyz\\/\">GitJoe<\\/a><\\/td><\\/tr>/' sedded_index.html >re_sedded_index.html"
+ "/usr/local/bin/gsed -i 's/<td><span class=\"desc\">Repositories<\\/span><\\/td>/<td><span class=\"desc\"><h1>" . $user . " - Repositories<\\/h1><\\/span><\\/td><\\/tr><tr><td><\\/td><td>Back to <a href=\"https:\\/\\/git.jozanleclerc.xyz\\/\">GitJoe<\\/a><\\/td><\\/tr>/' index.html"
);
- unlink('./sedded_index.html');
system(
'/usr/local/bin/dash',
'-c',
- "/usr/bin/sed 's/log.html/files.html/g' re_sedded_index.html >index.html"
+ "/usr/local/bin/gsed -i 's/log.html/files.html/g' index.html"
);
- unlink('./re_sedded_index.html');
return;
}
@@ -92,11 +89,15 @@ sub main {
}
closedir(DIR);
$i = 0;
+ mkdir(TMP_DIR, 0755);
while ($i < @users) {
my @repos = get_repos_index($users[$i]);
stagit_generate($users[$i], @repos);
+ print "Removing user " . colored($users[$i], 'bold green') . " old directory from " . colored(SITE_DIR, 'bold') . ".\n";
+ print "Moving user " . colored($users[$i], 'bold green') . " newly generated directory to " . colored(SITE_DIR, 'bold') . ".\n";
$i += 1;
}
+ rmdir(TMP_DIR);
print "Updated GitJoe index.\n";
exit;
}