From 07882e9d17e6b6f7433f592f6c17097706c83635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Klime=C5=A1?= <xklimes5@fi.muni.cz> Date: Fri, 5 Nov 2021 11:27:14 +0100 Subject: [PATCH] fix grammar, wording and code style --- README.md | 8 +++++--- cron.pl | 18 +++++++++++------- install.pl | 30 +++++++++++++++--------------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a3d0a84..d4e48eb 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,9 @@ For example, to install the printer `lj2b`, run ./install.pl lj2b ``` -After running the script, you will be prompted for your faculty credentials (the faculty username and the faculty password) and for cron installation if not already installed. +Installation script will prompt you for your faculty credentials (the faculty username and the faculty password). + +You will be also asked if you want to install cron script for automatic updates if not already installed. You may be prompted for the faculty credentials once again on the first print job, depending on your distribution. @@ -72,8 +74,8 @@ at <https://www.fi.muni.cz/tech/unix/print.html>. ## Repository structure | File | Description | -|------------------------ |------------------------------------------------ | +|------------------------- |------------------------------------------------- | | `install.pl` | main install script | -| `cron.pl` | cron script for updating PPDs | +| `cron.pl` | cron script for automatic updates | | `filters` | folder with filters for CUPS | | `ppds` | folder with PPDs for CUPS | diff --git a/cron.pl b/cron.pl index 4cf9999..b99f7a7 100755 --- a/cron.pl +++ b/cron.pl @@ -2,23 +2,26 @@ use File::Copy; use strict; -if (-d "/opt/fi-printers") { +my $REPO = "/opt/fi-printers"; - chdir "/opt/fi-printers"; +if (-d $REPO) { - my $output = `git pull --ff-only`; + chdir $REPO; + + my $output = `git pull --ff-only`; if ($output eq "Already up to date.\n") { exit; } } else { - my $output = `git clone https://gitlab.fi.muni.cz/unix/fi-printers.git /opt/fi-printers`; - chdir "/opt/fi-printers"; + `git clone https://gitlab.fi.muni.cz/unix/fi-printers.git $REPO`; + chdir $REPO; } # copy cron.pl into weekly cron -copy("/opt/fi-printers/cron.pl", "/etc/cron.weekly/fi_printers_cron"); +copy("$REPO/cron.pl", "/etc/cron.weekly/fi_printers_cron") + or die "Could not update /etc/cron.weekly/fi_printers_cron"; my @files = glob('/etc/cups/ppd/*fi.muni.ppd'); @@ -29,7 +32,8 @@ for my $item (@files) { } for my $printer (@files) { - system("/opt/fi-printers/install.pl --update $printer"); + system("$REPO/install.pl --update $printer") + or warn "Error while updating $printer"; } diff --git a/install.pl b/install.pl index f2c2de3..ab63d97 100755 --- a/install.pl +++ b/install.pl @@ -22,15 +22,15 @@ my $printers = { }, 'lj5c' => { 'model' => 'hplj600', - 'location' => 'Building C, 5th floor, next to copy', + 'location' => 'Building C, 5th floor', }, 'lj4c' => { 'model' => 'hplj600', - 'location' => 'Building C, 4th floor, next to copy', + 'location' => 'Building C, 4th floor', }, 'lj4p' => { 'model' => 'hpljp4015x', - 'location' => 'Building B, 4th floor, next to copy', + 'location' => 'Building B, 4th floor', }, 'lj4a' => { 'model' => 'hplj600', @@ -70,7 +70,7 @@ my $printers = { }, 'lj2b' => { 'model' => 'hpljp3015', - 'location' => 'Building B, 2nd floor, kitchen', + 'location' => 'Building B, 2nd floor kitchen', } }; @@ -119,17 +119,17 @@ sub get_description { } sub prompt_username { - print "[PROMPT] Enter username: "; + print "Enter username: "; chomp(my $username = <STDIN>); return $username; } sub prompt_password { - print "[PROMPT] Enter password: "; + print "Enter password: "; system("stty -echo"); chomp(my $password1 = <STDIN>); system("stty echo"); - print "\n[PROMPT] Repeat password: "; + print "\nRepeat password: "; system("stty -echo"); chomp(my $password2 = <STDIN>); system("stty echo"); @@ -149,7 +149,7 @@ sub get_url { my ($printer_name) = @_; my $user = encode_uri(prompt_username()); say "Warning! Password will be stored in plain text in /etc/cups/printers.conf"; - say "This is limitation of the CUPS/SMB method. To exit press Ctrl + c."; + say "This is a limitation of the CUPS/SMB method. To exit press Ctrl + c."; my $password = encode_uri(prompt_password()); $printer_name = encode_uri($printer_name); @@ -235,7 +235,7 @@ sub print_printers { sub usage { print <<END; Script for installing faculty printers on Linux via Samba print server. -usage: $0 (--cron|[--update] <printer-name>) +usage: $0 {--cron | [--update] <printer-name>} Requires local CUPS server running and Samba client installed. Must be run as root. @@ -255,7 +255,7 @@ sub check_python { if ($? == 0 && $output =~ $regex) { say "[OK] Python 2.7 is present."; - return "python "; + return "python"; } say "[ERROR] Python 2.7 is not present"; @@ -263,7 +263,7 @@ sub check_python { my $s_output = qx/python2 -V 2>&1/; if ($? == 0 && $s_output =~ $regex) { say "[OK] Python 2.7 is present as python2"; - return "python2 "; + return "python2"; } die "[ERROR] Python 2.7 Not Found and is needed for TA5007ci\n"; @@ -289,7 +289,7 @@ sub python_package { } sub pre_TA5007ci { - my $python = check_python; + my $python = check_python(); python_package("PyPDF2-1.26.0", $python); python_package("reportlab", $python); return; @@ -297,7 +297,7 @@ sub pre_TA5007ci { sub check_cron { if (! -e "/etc/cron.weekly/fi_printers_cron") { - print "[PROMPT] Do you want to enable automatic updates via cron? [Y/n] "; + print "Do you want to enable automatic updates via cron? [Y/n] "; chomp(my $answer = <STDIN>); if ($answer eq 'Y' || $answer eq 'y' || $answer eq '') { @@ -317,7 +317,7 @@ sub check_env { # Check for smbclient my $output = `which smbclient &>/dev/null`; if ($? != 0) { - die "[ERROR] Samba client seems not to be installed. (smbclinet)"; + die "[ERROR] Samba client seems not to be installed. (smbclient)"; } # Check if we don't have Root @@ -331,7 +331,7 @@ my ($printer_name) = @ARGV; if (not(exists($printers->{$printer_name}))) { say "[ERROR] Printer $printer_name is not supported."; - print_printers; + print_printers(); exit 1; } -- GitLab