Commit Diff
Diff:
/dev/null
9d3839a0be3481bf65cf46162be4ac4d9eedffcf
Commit:
9d3839a0be3481bf65cf46162be4ac4d9eedffcf
Tree:
72b93adca631bfbbe818e6169fc5bcc0af020656
Author:
Izzy Blacklock <izzyb@planetofnix.com>
Committer:
Izzy Blacklock <izzyb@planetofnix.com>
Date:
Tue May 23 02:58:08 2023 UTC
Message:
Final versions of the gitgot tools as desgribed on the wiki https://wiki.ircnow.org/index.php?n=Got.RemoteRepo
blob - /dev/null
blob + aeaaaabf41e969c684a1cd33480c06ed8ef043f4 (mode 755)
--- /dev/null
+++ gitgot-deploy.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+my $config={
+ stageDir=>'/var/gitgot',
+ gitgotUser=>'gitgot',
+ gotwebDir=>'/var/www/got/public',
+};
+# Sync changes from stageDir to the webdir
+opendir (my $DH, $config->{stageDir})
+ or die "Can't opendir " . $config->{stageDir} . " : $!";
+while (my $user = readdir($DH)) {
+ next if ($user =~ /^\./); # skip . files
+ if (-d $config->{stageDir} . "/$user") {
+ # Need the name of each repo so we can add username ass prefix
+ opendir (my $uDH, $config->{stageDir} . "/$user")
+ or die "Can't opendir ". $config->{stageDir} . "/$user/ : $!";
+ while (my $repo = readdir($uDH)) {
+ next if ($repo =~ /^\./); # skip . files
+ # need destination folder name to change to prefix
+ # the username to it to prevent one user from clobbering
+ # another users repos. Can't do a rename of the folder
+ # with rsync so have to create the destination folder then
+ # rsync the contents of it.
+ my @stat=stat($config->{stageDir} . "/$user/$repo");
+ my $prefixName="$user-$repo";
+ my $dst=qq(/$config->{gotwebDir}/$prefixName/);
+ mkdir $dst,$stat[2]; #stat[2] is mode of original dir
+ opendir (my $rDH, $config->{stageDir} . "/$user/$repo")
+ or die "Can't opendir ". $config->{stageDir} . "/$user/$repo : $!";
+ while (my $git = readdir($rDH)) {
+ next if ($git eq '.' or $git eq '..'); # skip . and ..
+
+ my $src=qq($config->{stageDir}/$user/$repo/$git);
+ my $rv=system(qq{
+ openrsync --rsync-path=openrsync -a --delete $src $dst
+ });
+ warn "rsync failed $prefixName\n$!\n" if ($rv != 0);
+ }
+ }
+ }
+}
+
blob - /dev/null
blob + c12ada8720bd30b26a5b4cc3ee48518b9dd18fb1 (mode 755)
--- /dev/null
+++ gitgot-staging.pl
@@ -0,0 +1,73 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+my $config={
+ remoteHost=>'got.ircnow.org',
+ remoteUser=>'gitgot',
+ remoteStage=>'/var/gitgot',
+ repoDir=>'public/gitgot',
+ createRepoDir=>1,
+ stageDir=>'/var/gitgot',
+ gitgotUser=>'gitgot',
+ key_path=>'/home/gitgot/.ssh/id_ed25519',
+ rsync_cmd=>'openrsync',
+};
+# verify we have a local staging area
+if (not -d $config->{stageDir}) {
+ my (undef,undef,$uid,$gid) = getpwnam($config->{gitgotUser})
+ or die "User " . $config->{gitgotUser} . " doesn't exist";
+ mkdir $config->{stageDir}, 0750;
+ chown $uid,$gid,$config->{stageDir};
+}
+opendir (my $DH, '/home/') || die "Can't opendir /home : $!";
+while (my $user = readdir($DH)) {
+ if (-d "/home/$user/" . $config->{repoDir}) {
+ # Skip if no repos
+ opendir (my $RDH, "/home/$user/" . $config->{repoDir})
+ or die "Can't opendir /home/$user/ : $!";
+ my @repos = readdir($RDH);
+ next unless (scalar @repos > 2);
+
+ # Make sure user has a staging directory
+ if(not -d $config->{stageDir} . "/$user") {
+ mkdir ($config->{stageDir} . "/$user");
+ }
+ # rsync files to local staging area
+ my $src=qq(/home/$user/$config->{repoDir}/*);
+ my $dst=qq($config->{stageDir}/$user/);
+ my $rv=system(qq{
+ openrsync --rsync-path=openrsync -a --delete $src $dst
+ });
+ warn "rsync failed $user\n$!\n" if ($rv != 0);
+ } elsif ($config->{createRepoDir}) { # create missing repo dirs
+ # skip dirs without users.
+ my (undef,undef,$uid,$gid) = getpwnam($user) or next;
+ my $repoPath="/home/$user";
+ for my $dir (split('/', $config->{repoDir})) {
+ $repoPath.="/$dir";
+ unless (-e $repoPath) {
+ mkdir $repoPath, 0755;
+ chown $uid,$gid,$repoPath;
+ }
+ }
+ }
+}
+
+# rsync to remote staging area if we have a remote host
+if (defined $config->{remoteHost}) {
+ # Only sync if we have repos to deploy
+ opendir (my $SDH, $config->{stageDir})
+ or die "Can't opendir ". $config->{stageDir} . " : $!";
+ my @repos = readdir($SDH);
+
+ if(scalar @repos > 2) {
+ my $src=$config->{stageDir} . "/*";
+ my $dst=$config->{gitgotUser}. "@" . $config->{remoteHost}
+ . ":" . $config->{remoteStage} . "/";
+ my $rv=system("openrsync --rsync-path=openrsync -ae "
+ . '"ssh -i ' . $config->{key_path}. '" --delete'
+ . " $src $dst "
+ );
+ }
+}
+
IRCNow