#!/usr/bin/perl
# Creates an updates.txt file based on existing module files

@dirs = ( "/home/virtualmin/domains/software.virtualmin.com/public_html/gpl/wbm" );

# Find all available files
foreach $dir (@dirs) {
    opendir(DIR, $dir);
    foreach $f (readdir(DIR)) {
        next if ($f !~ /^([a-z\-]+)\-([0-9gpl[^\.]+)\.(wbm|wbt)(\.gz)?$/);
        $mod = $1;
        $ver = $2;
	      next if ($1 eq "virtualmin-nuvola");	# broken
        $ver =~ s/\-//g;
        $path = "$dir/$f";
        $path =~ s/^.*public_html//g;
        if ($ver > $bestver{$mod}) {
            $bestver{$mod} = $ver;
            $bestfile{$mod} = $path;
            }
        }
    closedir(DIR);
    }

# Print them out
foreach $mod ('virtual-server',
              (grep { $_ ne 'virtual-server' } (keys %bestfile))) {
    print join("\t", $mod, $bestver{$mod}, $bestfile{$mod}, 0,
                     "Latest version"),"\n";
    }

