cron.pl 771 Bytes
Newer Older
1
#!/usr/bin/perl -w
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
2
3
4
use File::Copy;
use strict;

5
my $REPO = "/opt/fi-printers";
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
6

7
if (-d $REPO) {
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
8

9
10
11
    chdir $REPO;

    my $output = `git pull --ff-only`;
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
12
    if ($output eq "Already up to date.\n") {
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
13
        exit;
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
14
15
16
17
    }
}
else
{
18
19
    `git clone https://gitlab.fi.muni.cz/unix/fi-printers.git $REPO`;
    chdir $REPO;
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
20
21
22
}

# copy cron.pl into weekly cron
23
24
copy("$REPO/cron.pl", "/etc/cron.weekly/fi_printers_cron")
    or die "Could not update /etc/cron.weekly/fi_printers_cron";
25

Martin Klimeš's avatar
Martin Klimeš committed
26
my @files = glob('/etc/cups/ppd/*@fi.ppd');
27
28

for my $item (@files) {
29
30
    print "current $item\n";
    $item =~ s/\/etc\/cups\/ppd\///;
Martin Klimeš's avatar
Martin Klimeš committed
31
    $item =~ s/\@fi\.ppd//;
32
33
34
}

for my $printer (@files) {
35
36
    system("$REPO/install.pl --update $printer")
        or warn "Error while updating $printer";
37
}
Martin Klimes (k11m1)'s avatar
Martin Klimes (k11m1) committed
38
39