[perl subs=1] our ($mirrors, $avoids, $weights, $downloaders) = initialize_mirror_data(); return; [/perl] [if cgi selector] Here's the Nekoware package list.
Decide on general install parameters, click the checkboxes for the packages you want, and push the magic button.
[form-session-id]

Mirrors not to use:
[calc] my @ret; for (keys %$mirrors) { push @ret, " $_ "; } join("
", @ret); [/calc]

Downloader to use:
Wget [comment] Inst [/comment]
Don't generate inst line? (implies no cache)
No, please don't

Force regeneration, avoid cache?
Yes. Believe me, I know what I'm doing!

The output wanted is ...
HTML, in this browser window
Shell script, MIME type and all
[comment] Direct from-browser install (not yet)
[/comment]


[button text="__BUTTONTEXT__"] mv_nextpage=@@MV_PAGE@@ nekoresults=1 [/button]

[table-organize cols=4 table='width=90%'] [query ml=5000 more=0 sql="select filename,pkgname from packages order by pkgname" type=list] [list] [perl] return "" if "[sql-param pkgname]" =~ /^lib/ [/perl] [sql-param pkgname] [perl] return "" if "[sql-param pkgname]" =~ /^lib/ [/perl] [/list] [no-match] No packages match the criteria. [/no-match] [/query] [/table-organize]
[button text="__BUTTONTEXT__"] mv_nextpage=@@MV_PAGE@@ nekoresults=1 [/button]

[/if] [if cgi nekoresults] [tag flag write]cache[/tag] Wanna see the show, ay?

[perl tables="packages cache" interpolate=0 subs=1] my $ret; my (@files, @paks); for my $pak ( keys %$CGI) { next unless $pak =~ s/^pkg_//; my $file = $Tag->data({ table => 'packages', column => 'filename', foreign => 'pkgname', key => $pak, }); next unless $file; push @paks, $pak; push @files, $file; } @files = grep {!/^\s*$/} @files; @paks = grep {!/^\s*$/} @paks; @paks = sort @paks; @files = sort @files; my $watermark = $#files; # Index of last really requested package # Bail out on obvious unless ( scalar @paks or scalar @files ) { return 'Playing smart, eh? Go back and select some packages first.' } if ( @files > 100 ) { return 'Requesting A HUNDRED packages in one go is MAXIMUM, sorry.' } $ret .= "#!/bin/sh\n\n"; $ret .= "# Auto-generated script for SGI IRIX NEKOWARE\n" . "# package and dependencies download and installation.\n\n"; $ret .= "# Davor Ocelic, docelic\@mail.inet.hr, http://irix.plsavez.hr\n" . "# Nekochan, http://www.nekochan.net\n\n"; $ret .= '# Requested packages: ' . join(' ', @paks) . "\n"; # Cache deal my $file = join("_", @paks[0..$watermark]) . '.sh'; -r $file and $cached = readfile($file); my $work_done; if ($cached ) { unless ( $CGI->{nocache} ) { $ret = $cached; $work_done++; } } unless ( $work_done ) { # Now, now. for (my $i=0; $i < @files; $i++) { my $file = $files[$i]; my $deps = $Tag->data('packages','dependencies',$file); if ( $deps and $deps ne "no dependencies" ) { my @deps = split /,+/, $deps; for my $dep (@deps) { my $filename = $Tag->data({ table => 'packages', field => 'filename', foreign => 'pkgname', key => $dep, }); next unless $file and $deps; push(@files, $filename) unless grep {/^$filename$/} @files; push(@paks, $dep) unless grep {/^$dep$/} @paks; } } # Drop in a safety if ( $i > 2000 ) { $ret .= "LOOP MAX 1! Report to docelic@mail.inet.hr\n"; last } } @files = grep {!/^\s*$/} @files; @paks = grep {!/^\s*$/} @paks; my @mirrors = ( keys %$mirrors ); my $lc; for ( my $i =0; $i<@files; $i++) { $_ = $files[$i]; if ($i == $watermark +1 ) { $ret .= "\n# Dependency packages:\n"; } my ( $loc, %seen ); # Detect if user ruled out all mirrors my @eliminated = grep {/mirr_/} keys %$CGI; if ( scalar @eliminated == scalar keys %$mirrors ) { return "Want me to work with no mirrors 1? That's a no-go."; } my $lc2; do { $loc = $mirrors[int rand($#mirrors+1)]; } while ( ( !$loc or $CGI->{"mirr_" . $loc} ) and $lc2++ < 2000 ); if ( $lc2 >= 2000 ) { $ret .= "LOOP MAX 2! Report to docelic@mail.inet.hr\n"; last } $loc = $$mirrors{$loc}; # Drop in a safety if ( $lc++ > 2000 ) { $ret .= "LOOP MAX 3! Report to docelic@mail.inet.hr\n"; last } my $downloader = $$downloaders{$CGI->{downloader}}; unless ( $downloader ) { return "Invalid downloader 1 hey?! Playing smart or what."; } $ret .= "$downloader '" . $_ . "' \\\n\t'$loc" . $_ . "'\n"; } if ( ! $CGI->{noinst} ) { $ret .= "\n# Run inst:\n/usr/sbin/inst \\\n" . join(" \\\n", (map {"\t-f $_"} @files)) . "\n\n"; } else { $ret .= "\n# Inst line not generated by request.\n\n"; } for ( @paks[0..$watermark] ) { $Db{cache}->set_field($_, 'times', ($Tag->data('cache', 'times', $_)||0) + 1); } $Tag->tag(qw/export cache/); } # Aaand, here we go! my $wrote = write_script_file ( join("_", @paks[0..$watermark]) . '.sh', $ret ); my $url = "http://irix.plsavez.hr/scripts/" . $wrote; if ( $CGI->{output} eq 'html' ) { return "

" . $ret . "
"; } elsif ( $CGI->{output} eq 'sh' ) { return "Your selection has been generated and can be dowloaded:
\n" . "$url

" . "It will stay there for a while (or at least until the mirror " . "contents don't change), so feel free to re-download it at will."; } else { return "Format not implemented."; } [/perl] [/if]