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

if (-d "/opt/fi-printers") {

    chdir "/opt/fi-printers";

    my $output  = `git pull --ff-only`;
    if ($output eq "Already up to date.\n") {
        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_cron");

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) {
	system("/opt/fi-printers/install.pl --update $printer");
}


