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

better options + readme

parent f953fbb7
......@@ -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` |
......@@ -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");
......
......@@ -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();
......@@ -286,7 +297,7 @@ sub pre_TA5007ci {
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]";
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 '') {
......@@ -294,9 +305,22 @@ 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.";
}
}
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
......@@ -304,20 +328,12 @@ sub check_cron {
my ($printer_name) = @ARGV;
# Check for smbclient
my $output = `which smbclient &>/dev/null`;
if ($? != 0) {
die "[ERROR] Samba client seems not to be installed. (smbclinet)";
}
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";
......
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