+
+my @specoceans;
+my $alloceans;
+my $backup;
+
+sub optarg () {
+ return $_ if length;
+ die unless @ARGV;
+ return scalar shift @ARGV;
+}
+
+while (@ARGV && $ARGV[0] =~ m/^-/) {
+ $_= shift @ARGV;
+ last if m/^--?$/;
+ while (m/^-./) {
+ if (s/^-d//) {
+ die if defined $rsyncdir;
+ $rsyncdir= optarg();
+ } elsif (s/^-O//) {
+ push @specoceans, optarg();
+ } elsif (s/^-b/-/) {
+ die if $backup;
+ $backup=1;
+ } elsif (s/^-a/-/) {
+ die if $alloceans;
+ $alloceans=1;
+ } else {
+ die "$_ ?";
+ }
+ }
+}
+die if @ARGV;
+
+die if @specoceans && $alloceans;
+die if $backup && !$alloceans && !@specoceans;
+
+parse_info_serverside();
+
+if ($backup) {
+ my @oceans= $alloceans ? (sort keys %oceans) : @specoceans;
+ foreach my $ocean (@oceans) {
+ print "## database backup for $ocean\n";
+ db_setocean($ocean);
+ db_writer();
+ db_connect();
+ $dbh->selectall_arrayref("SELECT * FROM commods WHERE commodid=1");
+ my $src= db_filename();
+ my $dst= $src; $dst =~ s,.*/,,; $dst= "$rsyncdir/$dst";
+ copy($src,"$dst.tmp") or die "$src -> $dst.tmp $!";
+ rename("$dst.tmp",$dst) or die "$dst.tmp -> $dst $!";
+ $dbh->rollback();
+ }
+} elsif (@specoceans) {
+ print "### full update of specified oceans ...\n";
+ foreach my $ocean (@specoceans) {
+ die "$ocean ?" unless defined $oceans{$ocean};
+ full($ocean);
+ }
+} elsif ($alloceans) {
+ print "### full (inc.topology) update of all oceans ...\n";
+ foreach my $ocean (sort keys %oceans) {
+ full($ocean);
+ }
+} else {
+ print "### quick (no topology) update only (of all oceans) ...\n";
+ foreach my $ocean (sort keys %oceans) {
+ quick($ocean);
+ }
+}
+
+if (defined $rsyncdir and !$backup) {
+ print "### master-info update ...\n";
+ update_master_info();
+}