Commit 6f66ba27 authored by Martin Klimes (k11m1)'s avatar Martin Klimes (k11m1)
Browse files

auto updater via cron

parent ae104d18
......@@ -31,7 +31,9 @@ If you are printing with unauthenticated IPP or Kerberized IPP, you will have to
## Usage
Usage: `./install.pl <printer-name>` , where `<printer-name>` is a valid printer name. For example, to install printer `lj2b` run
Usage: `./install.pl [--usage] <printer-name>` , where `<printer-name>` is a valid printer name. If supplied `--usage` script will only update drivers.
For example, to install printer `lj2b` run
```shell
./install.pl lj2b
......
#!/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 $message = "Already up to date.";
my $output = `git pull --ff-only`;
if ($output eq "Already up to date.\n") {
print "Nothing to do";
exit;
}
print $output;
my @files = glob( '/etc/cups/ppd/*.ppd' );
......@@ -22,5 +36,9 @@ for my $item (@files) {
}
for my $printer (@files) {
system("./install.pl --update $printer")
my $command = "/opt/fi-printers/install.pl --update $printer";
print "$command \n";
system($command);
}
......@@ -10,23 +10,10 @@ use File::Copy;
use File::Basename;
use Getopt::Long qw(:config bundling);
#my $opt = {
#};
#--------------------------------------------------------------------
# Option processing
# DATA
#--------------------------------------------------------------------
my $only_update = '';
my $only_usage = '';
GetOptions(
'update' => \$only_update,
'help|h|?' => \$only_usage
) or die;
########
# DATA #
########
my $printers = {
'copy4b' => {
......@@ -111,9 +98,24 @@ my $models = {
}
};
###############
# END OF DATA #
###############
#--------------------------------------------------------------------
# Option processing
#--------------------------------------------------------------------
my $only_update = '';
my $only_usage = '';
GetOptions(
'update' => \$only_update,
'help|h|?' => \$only_usage
) or die;
if ($only_usage || @ARGV != 1) {
usage();
}
#--------------------------------------------------------------------
# Helper functions
#--------------------------------------------------------------------
sub get_description {
my ($printer_name) = @_;
......@@ -225,11 +227,12 @@ sub usage {
say
"Script for installing faculty printers on Linux via Samba print server.";
say "Requires local CUPS server running and Samba client installed.";
say "usage: $0 <printer-name>";
say "usage: $0 [--update] <printer-name>";
say "Must be run as root.";
say "Triumph-Adler 50007ci needs Python 2.7 as a dependency";
say "and will install 2 additional python modules automatically.";
print "\n\n";
say "Option --update only updates installed printer";
print "\n";
print_printers();
exit 1;
......@@ -281,14 +284,22 @@ sub pre_TA5007ci {
return;
}
#######################
# START OF THE SCRIPT #
#######################
# Show help
if ($only_usage || @ARGV != 1) {
usage();
sub check_cron {
if (! -e "/etc/cron.weekly/fi_printers_cron.pl") {
print "[PROMPT] Do you want to enable automatic updates via cron? [Y/n]";
chomp(my $answer = <STDIN>);
if ($answer eq 'Y' || $answer eq 'y' || $answer eq '') {
print "CRON SHALL BE INSTALLED\n";
copy("cron.pl", "/etc/cron.weekly/fi_printers_cron.pl")
or die "Could not copy cron script\n";
chmod 0700, "/etc/cron.weekly/fi_printers_cron.pl"
}
}
}
#--------------------------------------------------------------------
# Start of the script
#--------------------------------------------------------------------
my ($printer_name) = @ARGV;
......@@ -320,9 +331,11 @@ for my $filter (@{($models->{$model} // {})->{filters} // []}) {
}
if ($only_update) {
update_ppd("$printer_name");
say "[INFO] Update is completed.";
say "[INFO] Update of $printer_name is completed.";
}
else {
install_printer("$printer_name");
say "[INFO] Installation is completed.";
say "[INFO] Installation of $printer_name is completed.";
check_cron();
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment