From 9a7549470b7e9589c1b48354114b988cd27aacdf Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Thu, 30 Jul 2020 01:00:48 +0200 Subject: Gitjoe update script changes --- src/update/gitjoe.pl | 35 ++++++++++++++++++----------------- 1 file 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/" . $user . "<\\/td>/" . $user . "<\\/td>/g' index.html >sedded_index.html" + "/usr/local/bin/gsed -i 's/" . $user . "<\\/td>/" . $user . "<\\/td>/g' index.html" ); system( '/usr/local/bin/dash', '-c', - "/usr/bin/sed 's/Repositories<\\/span><\\/td>/

" . $user . " - Repositories<\\/h1><\\/span><\\/td><\\/tr><\\/td>Back to GitJoe<\\/a><\\/td><\\/tr>/' sedded_index.html >re_sedded_index.html" + "/usr/local/bin/gsed -i 's/Repositories<\\/span><\\/td>/

" . $user . " - Repositories<\\/h1><\\/span><\\/td><\\/tr><\\/td>Back to 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; } -- cgit v1.2.3