#!/usr/bin/perl -w

use strict;

my $dir = "patch/";
opendir my $dh, $dir || die "can't open dir $!";
my @filesList = readdir($dh);
closedir $dh;
foreach my $file (@filesList) {
  unless ( ($file eq ".") || ($file eq "..") ) {
    my @cmd = `vihostupdate --server $ARGV[0] --username root --password ******* -b patch/$file -l`;
    for my $i(2..$#cmd) {
      my $patch=(split( /\s/, $cmd[$i]))[0];
      print "Patching $ARGV[0] with patch $patch from file $file\n";
      `vihostupdate --server $ARGV[0] --username root --password ******* -i -b patch/$file -B $patch`;
      }
    }
}