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

better options + readme

parent f953fbb7
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ Script for installing faculty printers on Linux via Samba print server.
-   running local [CUPS](https://www.cups.org/) print server
-   Samba client (`smbclient`)
-   Python2 for `copy4a` and `copy5b`
-   Cron system for automatic update


### Warning
@@ -31,7 +32,7 @@ If you are printing with unauthenticated IPP or Kerberized IPP, you will have to

## Usage

Usage: `./install.pl [--usage] <printer-name>` , where `<printer-name>` is a valid printer name. If supplied `--usage` script will only update drivers.
Usage: `./install.pl (--cron|[--usage] <printer-name>)` , where `<printer-name>` is a valid printer name. If supplied `--usage` script will only update drivers. Passing --cron will only prompt user for cron installation.

For example, to install printer `lj2b` run

@@ -39,7 +40,7 @@ For example, to install printer `lj2b` run
./install.pl lj2b
```

After running the script, you will be prompted for you faculty login(username and password).
After running the script, you will be prompted for you faculty login(username and password) and for cron instalation if not already installed.


### Available printers
@@ -71,6 +72,7 @@ You can find out more information on <https://www.fi.muni.cz/tech/unix/print.htm
| File                     | Description                                      |
|------------------------ |------------------------------------------------ |
| `install.pl`             | main install script                              |
| `cron.pl`                | cron script for updating PPDs                    |
| `filters`                | folder with filters for CUPS                     |
| `ppds`                   | folder with PPDs for CUPS                        |
| `PyPDF2` and `reportlab` | folder with Python 2 dependencies for `TA5007ci` |
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ else
}

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



+30 −14
Original line number Diff line number Diff line
@@ -104,15 +104,25 @@ my $models = {

my $only_update = '';
my $only_usage = '';
my $only_cron = '';

GetOptions(
    'update'     => \$only_update,
    'help|h|?'   => \$only_usage
    'cron'       => \$only_cron,
    'help|h|?'   => \$only_usage,
) or die;

if ($only_usage || @ARGV != 1) {
if ($only_usage || (@ARGV != 1 && !$only_cron)) {
   usage();
}

check_env();

if ($only_cron) {
    check_cron();
    exit;
}

#--------------------------------------------------------------------
#  Helper functions
#--------------------------------------------------------------------
@@ -227,11 +237,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 [--update] <printer-name>";
    say "usage: $0 (--cron|[--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.";
    say "Option --update only updates installed printer";
    say "Option --update only updates installed printer.";
    say "Option --cron only prompts for cron installation.";
    print "\n";
    print_printers();

@@ -294,30 +305,35 @@ sub check_cron {
            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";
            print "[INFO] Cron installed\n";
            say "[INFO] Cron installed";
        }
    } else {
        say "[INFO] Cron is already installed.";
    }
}
#--------------------------------------------------------------------
#  Start of the script
#--------------------------------------------------------------------

my ($printer_name) = @ARGV;

sub check_env {
    # Check for smbclient
    my $output = `which smbclient &>/dev/null`;
    if ($? != 0) {
        die "[ERROR] Samba client seems not to be installed. (smbclinet)";
    }

    # Check if we don't have Root
    die "[ERROR] Must be run with root privileges\n" if $> != 0;
}
#--------------------------------------------------------------------
#  Start of the script
#--------------------------------------------------------------------

my ($printer_name) = @ARGV;

if (not(exists($printers->{$printer_name}))) {
    say "[ERROR] Printer $printer_name is not supported.";
    print_printers;
    exit 1;
}

# Check if we have Root
die "[ERROR] Must be run with root privileges\n" if $> != 0;

my $model = $printers->{$printer_name}->{'model'};
say "[INFO] Selected model is $model";