Loading install.pl +29 −28 Original line number Diff line number Diff line Loading @@ -88,11 +88,11 @@ my $models = { ], }, 'TA4505ci' => { 'filters' => [ '/usr/libexec/cups/filter/kyofilter_B', ], 'options' => [ 'Option19=One', 'Option21=True', 'Option17=DF730', ], 'filters' => ['/usr/libexec/cups/filter/kyofilter_B',], 'options' => ['Option19=One', 'Option21=True', 'Option17=DF730',], }, 'hplj600' => { 'options' => [ 'HPOption_Duplexer=True', ], 'options' => ['HPOption_Duplexer=True',], } }; Loading @@ -107,22 +107,22 @@ sub get_description { sub prompt_username { print "[PROMPT] Enter username: "; chomp( my $username = <STDIN> ); chomp(my $username = <STDIN>); return $username; } sub prompt_password { print "[PROMPT] Enter password: "; system("stty -echo"); chomp( my $password1 = <STDIN> ); chomp(my $password1 = <STDIN>); system("stty echo"); print "\n[PROMPT] Repeat password: "; system("stty -echo"); chomp( my $password2 = <STDIN> ); chomp(my $password2 = <STDIN>); system("stty echo"); print "\n"; if ( $password1 ne $password2 ) { if ($password1 ne $password2) { die "[ERROR] Passwords do not match!"; } return $password1; Loading Loading @@ -152,7 +152,7 @@ sub install_printer { -o auth-info-required=username,password); for my $option ( @{ $models->{ $printers->{$printer_name}->{'model'} }->{'options'} } ) @{$models->{$printers->{$printer_name}->{'model'}}->{'options'}}) { $command .= " -o $option "; } Loading @@ -165,16 +165,16 @@ sub install_printer { sub copy_filter { my ($path) = @_; my ( $filter, $destination, $suffix ) = fileparse($path); my ($filter, $destination, $suffix) = fileparse($path); # my $destination = "/usr/lib/cups/filter/"; if ( !-d $destination ) { if (!-d $destination) { my $dirs = eval { mkpath($destination) }; die "[ERROR] Failed to create $destination $@\n" unless $dirs; } copy( "filters/" . $filter, $destination ) copy("filters/" . $filter, $destination) or die "[ERROR] Failed to copy $filter: $!\n"; say "[OK] Copied $filter."; Loading @@ -187,7 +187,7 @@ sub print_printers() { say "Available printers:"; printf "%-14s | %-12s| %s\n", "Printer name", "Model", "Location"; say "-" x 70; for ( sort keys %$printers ) { for (sort keys %$printers) { printf "%-14s | %-12s| %s\n", $_, $printers->{$_}->{'model'}, $printers->{$_}->{'location'}; } Loading @@ -195,7 +195,8 @@ sub print_printers() { } sub usage() { say "Script for installing fi printers on Linux via Samba print server."; 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 "Must be run as root."; Loading @@ -211,7 +212,7 @@ sub check_python { my $regex = qr/^Python 2\.7*/; my $output = qx/python -V 2>&1/; if ( $? == 0 && $output =~ $regex ) { if ($? == 0 && $output =~ $regex) { say "[OK] Python 2.7 is present."; return "python "; } Loading @@ -219,7 +220,7 @@ sub check_python { say "[ERROR] Python 2.7 is not present"; my $s_output = qx/python2 -V 2>&1/; if ( $? == 0 && $s_output =~ $regex ) { if ($? == 0 && $s_output =~ $regex) { say "[OK] Python 2.7 is present as python2"; return "python2 "; } Loading @@ -228,19 +229,19 @@ sub check_python { } sub python_package { my ( $package_name, $python ) = @_; my ($package_name, $python) = @_; say "[INFO] Installing $package_name..."; my $status = chdir "$package_name"; if ( $status == 0 ) { if ($status == 0) { die "[ERROR] folder $package_name is not present!"; } my $output = system("${python} setup.py install"); if ( $? != 0 ) { if ($? != 0) { die "[ERROR] $package_name exited with different exit code than 0!"; } $status = chdir '..'; if ( $status == 0 ) { if ($status == 0) { die "[ERROR] Could not return to the working directory!"; } return; Loading @@ -248,8 +249,8 @@ sub python_package { sub pre_TA5007ci { my $python = check_python; python_package( "PyPDF2-1.26.0", $python ); python_package( "reportlab", $python ); python_package("PyPDF2-1.26.0", $python); python_package("reportlab", $python); return; } Loading @@ -257,11 +258,11 @@ sub pre_TA5007ci { # START OF THE SCRIPT # ####################### if ( @ARGV == 0 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help" ) { if (@ARGV == 0 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help") { usage; } if ( @ARGV != 1 ) { if (@ARGV != 1) { usage; } Loading @@ -269,11 +270,11 @@ my ($printer_name) = @ARGV; # Check for smbclient my $output = `which smbclient &>/dev/null`; if ( $? != 0 ) { if ($? != 0) { die "[ERROR] Samba client seems not to be installed. (smbclinet)"; } if ( not( exists( $printers->{$printer_name} ) ) ) { if (not(exists($printers->{$printer_name}))) { say "[ERROR] Printer $printer_name is not supported."; print_printers; exit 1; Loading @@ -286,12 +287,12 @@ my $model = $printers->{$printer_name}->{'model'}; say "[INFO] Selected model is $model"; #TA5007ci requires python2 reportlab and PyPDF2 if ( $model eq "TA5007ci" ) { if ($model eq "TA5007ci") { pre_TA5007ci; } for my $filter ( @{ ( $models->{$model} // {} )->{filters} // [] } ) { copy_filter $filter; for my $filter (@{($models->{$model} // {})->{filters} // []}) { copy_filter($filter); } install_printer "$printer_name"; Loading Loading
install.pl +29 −28 Original line number Diff line number Diff line Loading @@ -88,11 +88,11 @@ my $models = { ], }, 'TA4505ci' => { 'filters' => [ '/usr/libexec/cups/filter/kyofilter_B', ], 'options' => [ 'Option19=One', 'Option21=True', 'Option17=DF730', ], 'filters' => ['/usr/libexec/cups/filter/kyofilter_B',], 'options' => ['Option19=One', 'Option21=True', 'Option17=DF730',], }, 'hplj600' => { 'options' => [ 'HPOption_Duplexer=True', ], 'options' => ['HPOption_Duplexer=True',], } }; Loading @@ -107,22 +107,22 @@ sub get_description { sub prompt_username { print "[PROMPT] Enter username: "; chomp( my $username = <STDIN> ); chomp(my $username = <STDIN>); return $username; } sub prompt_password { print "[PROMPT] Enter password: "; system("stty -echo"); chomp( my $password1 = <STDIN> ); chomp(my $password1 = <STDIN>); system("stty echo"); print "\n[PROMPT] Repeat password: "; system("stty -echo"); chomp( my $password2 = <STDIN> ); chomp(my $password2 = <STDIN>); system("stty echo"); print "\n"; if ( $password1 ne $password2 ) { if ($password1 ne $password2) { die "[ERROR] Passwords do not match!"; } return $password1; Loading Loading @@ -152,7 +152,7 @@ sub install_printer { -o auth-info-required=username,password); for my $option ( @{ $models->{ $printers->{$printer_name}->{'model'} }->{'options'} } ) @{$models->{$printers->{$printer_name}->{'model'}}->{'options'}}) { $command .= " -o $option "; } Loading @@ -165,16 +165,16 @@ sub install_printer { sub copy_filter { my ($path) = @_; my ( $filter, $destination, $suffix ) = fileparse($path); my ($filter, $destination, $suffix) = fileparse($path); # my $destination = "/usr/lib/cups/filter/"; if ( !-d $destination ) { if (!-d $destination) { my $dirs = eval { mkpath($destination) }; die "[ERROR] Failed to create $destination $@\n" unless $dirs; } copy( "filters/" . $filter, $destination ) copy("filters/" . $filter, $destination) or die "[ERROR] Failed to copy $filter: $!\n"; say "[OK] Copied $filter."; Loading @@ -187,7 +187,7 @@ sub print_printers() { say "Available printers:"; printf "%-14s | %-12s| %s\n", "Printer name", "Model", "Location"; say "-" x 70; for ( sort keys %$printers ) { for (sort keys %$printers) { printf "%-14s | %-12s| %s\n", $_, $printers->{$_}->{'model'}, $printers->{$_}->{'location'}; } Loading @@ -195,7 +195,8 @@ sub print_printers() { } sub usage() { say "Script for installing fi printers on Linux via Samba print server."; 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 "Must be run as root."; Loading @@ -211,7 +212,7 @@ sub check_python { my $regex = qr/^Python 2\.7*/; my $output = qx/python -V 2>&1/; if ( $? == 0 && $output =~ $regex ) { if ($? == 0 && $output =~ $regex) { say "[OK] Python 2.7 is present."; return "python "; } Loading @@ -219,7 +220,7 @@ sub check_python { say "[ERROR] Python 2.7 is not present"; my $s_output = qx/python2 -V 2>&1/; if ( $? == 0 && $s_output =~ $regex ) { if ($? == 0 && $s_output =~ $regex) { say "[OK] Python 2.7 is present as python2"; return "python2 "; } Loading @@ -228,19 +229,19 @@ sub check_python { } sub python_package { my ( $package_name, $python ) = @_; my ($package_name, $python) = @_; say "[INFO] Installing $package_name..."; my $status = chdir "$package_name"; if ( $status == 0 ) { if ($status == 0) { die "[ERROR] folder $package_name is not present!"; } my $output = system("${python} setup.py install"); if ( $? != 0 ) { if ($? != 0) { die "[ERROR] $package_name exited with different exit code than 0!"; } $status = chdir '..'; if ( $status == 0 ) { if ($status == 0) { die "[ERROR] Could not return to the working directory!"; } return; Loading @@ -248,8 +249,8 @@ sub python_package { sub pre_TA5007ci { my $python = check_python; python_package( "PyPDF2-1.26.0", $python ); python_package( "reportlab", $python ); python_package("PyPDF2-1.26.0", $python); python_package("reportlab", $python); return; } Loading @@ -257,11 +258,11 @@ sub pre_TA5007ci { # START OF THE SCRIPT # ####################### if ( @ARGV == 0 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help" ) { if (@ARGV == 0 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help") { usage; } if ( @ARGV != 1 ) { if (@ARGV != 1) { usage; } Loading @@ -269,11 +270,11 @@ my ($printer_name) = @ARGV; # Check for smbclient my $output = `which smbclient &>/dev/null`; if ( $? != 0 ) { if ($? != 0) { die "[ERROR] Samba client seems not to be installed. (smbclinet)"; } if ( not( exists( $printers->{$printer_name} ) ) ) { if (not(exists($printers->{$printer_name}))) { say "[ERROR] Printer $printer_name is not supported."; print_printers; exit 1; Loading @@ -286,12 +287,12 @@ my $model = $printers->{$printer_name}->{'model'}; say "[INFO] Selected model is $model"; #TA5007ci requires python2 reportlab and PyPDF2 if ( $model eq "TA5007ci" ) { if ($model eq "TA5007ci") { pre_TA5007ci; } for my $filter ( @{ ( $models->{$model} // {} )->{filters} // [] } ) { copy_filter $filter; for my $filter (@{($models->{$model} // {})->{filters} // []}) { copy_filter($filter); } install_printer "$printer_name"; Loading