#!/usr/bin/perl -w
use File::Copy;
use strict;

if (-d "/opt/fi-printers") {
    #check
    print "Opt dir exits\n";
    my $output  = `git pull --ff-only`;
    if ($output eq "Already up to date.\n") {
        print "Nothing to do";
        # exit;
    }
}
else
{
    #clone
    my $output = `git clone https://gitlab.fi.muni.cz/unix/fi-printers.git /opt/fi-printers`;
}

# copy cron.pl into weekly cron
copy("/opt/fi-printers/cron.pl", "/etc/cron.weekly/fi-printers.pl");





my @files = glob( '/etc/cups/ppd/*.ppd' );


my @new_files = ();

for my $item (@files) {
	print "current $item\n";
	$item =~ s/\/etc\/cups\/ppd\///;
	$item =~ s/\.fi\.muni\.ppd//;
}

for my $printer (@files) {
    my $command = "/opt/fi-printers/install.pl --update $printer";
    print "$command \n";
	system($command);
}


