# ls ftp://ftp.lyx.org/pub/lyx/stable/lyx-*.tar.gz
# s/lyx-(.*)\.tar\.gz/\1/
# sort
# url = "ftp://ftp.lyx.org/pub/lyx/stable/lyx-$latest.tar.gz"

# open $0
# /^(## CurrentVersion:)(.*)$/
# exit if \2 = $latest
# s/^(## CurrentVersion:)$/\1$latest/
# s/^(## Url)$/\1$url/
# close

# versuchen wirs mal in perl
use Net::FTP;

$server = "ftp.lyx.org";
$dir = "/pub/lyx/stable";
$pattern = "lyx-(.+)\.tar\.gz";

$ftp = Net::FTP->new($server, Debug => 0, Passive => 1);
$ftp->login("anonymous",'-anonymous@');
$ftp->cwd($dir);
@list = $ftp->ls;
$ftp->quit;

@versions = grep(/$pattern/, @list);
@sorted = sort(@versions);
$latest = $sorted[$#sorted];
$url = "ftp://$server$dir/$latest";
$latest =~ s/$pattern/$1/;

open(SELF, "<$0");
@self = <SELF>;
chomp(@self);
close(SELF);

foreach $line (@self) {
  if ($line =~ /^## (CurrentVersion|Url):(.*)$/) {
    if ($1 eq Url) {
      $line = "## Url: $url";
    } else {
      $last = $2;
      $line = "## CurrentVersion: $latest";
    }
  }
}

if ($last eq $latest) { exit; }

open(SELF, ">$0");
print SELF join("\n", @self);
close(SELF);

## CurrentVersion:
## Url:

RonnyBuchmann/CurrentVersion/lyx (zuletzt geändert am 2007-12-23 22:45:15 durch localhost)