diff --git a/Dockerfile.planetgen b/Dockerfile.planetgen new file mode 100644 index 0000000..e5c6f0d --- /dev/null +++ b/Dockerfile.planetgen @@ -0,0 +1,17 @@ +FROM debian:12-slim +ADD ./planetgen /opt/planetgen +RUN <-- files at regular +# Checks the input dir for req--- files at regular # intervals and generate planets accordingly. # # Syntax : ./planetmaker.pl # -$outDir = "/mnt/planets"; +use strict; use warnings; -close(STDIN); -close(STDERR); -close(STDOUT); -if (fork()) -{ - exit(0); -} +use FindBin qw($Bin); +require File::Temp; +use File::Temp (); +use File::Temp qw/ :seekable /; -chdir("/opt/planetgen"); -mkdir("/tmp/pgen", 01777) if (! -d "/tmp/pgen"); -while (1) -{ - chop($find = `find /tmp/pgen/ -name 'req-*-*-*'`); - if ($find ne "") - { - @list = split /\n/, $find; +my $outDir = $ENV{PGEN_OUTPUT} || "/tmp/pgen-out"; +my $inDir = $ENV{PGEN_INPUT} || "/tmp/pgen-input"; - foreach my $name (@list) - { - unlink($name); - my ($junk,$version,$first,$count) = split /-/, $name; +chdir $Bin; +print "Entering main loop\n"; +print " Input directory: $inDir\n"; +print " Output directory: $outDir\n"; +mkdir($inDir, 01777) unless -d $inDir; +mkdir($outDir, 00755) unless -d $outDir; - for ($i=$first;$i<$first+$count;$i++) - { - my $fn = "/tmp/pgen/out.pov"; - `./generate.pl $fn`; - `povray +W80 +H80 +O$outDir/$version/l/$i.png -D -V $fn >/dev/null 2>&1`; - `povray +W30 +H30 +O$outDir/$version/s/$i.png -D -V $fn >/dev/null 2>&1`; - unlink($fn); - } +while (1) { + opendir(my $dir, $inDir) or die "Could not open $inDir: $! $_"; + my @list = grep { + -f "$inDir/$_" && /^req-[a-z0-9]+-\d+-\d+$/ + } readdir $dir; + close $dir; + + foreach my $name (@list) { + unlink("$inDir/$name"); + my ($junk,$version,$first,$count) = split /-/, $name; + print "Generating planets for $version.\n"; + print " First planet $first.\n"; + print " $count planets\n"; + + my $verDir = "$outDir/$version"; + foreach my $suffix ("", "/l", "/s") { + my $dir = $verDir . $suffix; + mkdir($dir) unless -d $dir + } + + for (my $i=$first;$i<$first+$count;$i++) { + my $fn = File::Temp->new(SUFFIX => '.pov'); + `./generate.pl $fn`; + `povray +W80 +H80 +O$verDir/l/$i.png -D -V $fn >/dev/null 2>&1`; + `povray +W30 +H30 +O$verDir/s/$i.png -D -V $fn >/dev/null 2>&1`; + unlink($fn); } } + sleep(60); + print "Sleeping...\n"; }