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

cleanup + Message enhancements

parent 73599deb
Loading
Loading
Loading
Loading
+27 −33
Original line number Diff line number Diff line
@@ -112,25 +112,24 @@ sub get_description {
}

sub prompt_username {
    print "Enter username: ";
    print "[PROMPT] Enter username: ";
    chomp( my $username = <STDIN> );
    return $username;
}

sub prompt_password {
    print "Enter password: ";
    print "[PROMPT] Enter password: ";
    system("stty -echo");
    chomp( my $password1 = <STDIN> );
    system('stty echo');
    print "\nRepeat password: ";
    print "\n[PROMPT] Repeat password: ";
    system('stty -echo');
    chomp( my $password2 = <STDIN> );
    system("stty echo");
    print "\n";

    if ( $password1 ne $password2 ) {
        say "Error: Passwords do not match!";
        exit 1;
        die "[ERROR] Passwords do not match!";
    }
    return $password1;
}
@@ -175,11 +174,11 @@ sub copy_filter {

    if ( !-d $destination ) {
        my $dirs = eval { mkpath($destination) };
        die "Failed to create $destination $@\n" unless $dirs;
        die "[ERROR] Failed to create $destination $@\n" unless $dirs;
    }

    copy( "filters/" . $filter, $destination )
      or die "Failed to copy $filter: $!\n";
      or die "[ERROR] Failed to copy $filter: $!\n";
    say "[OK] Copied $filter.";

    chmod( 755, $destination . $filter );
@@ -212,28 +211,24 @@ sub usage() {

sub check_python {
    my $regex  = qr/^Python 2\.7*/;

    #FIXME Use of unitialized value $_ in pattern match
    my $output = qx/python -V 2>&1/;

    if ( $? == 0 && $output =~ $regex ) {
        say "[OK] Python 2.7 is present.";
        return "python ";
    }
    else {

    # TODO FIXME ADD python2
    say "[ERROR] Python 2.7 is not present";

    # TRY python2 command
    my $s_output = qx/python2 -V 2>&1/;
    if ( $? == 0 && $s_output =~ $regex ) {
            say "ASI OK, TESTING NEEDED";    # TODO OTESTOVAT
        say "[OK] Python 2.7 is present as python2";    # TODO OTESTOVAT
        return "python2 ";
    }
        else {
            die "Python 2.7 Not Found and is needed for TA5007ci\n";
        }
    }

    die "[ERROR] Python 2.7 Not Found and is needed for TA5007ci\n";
}

sub python_package {
@@ -242,15 +237,15 @@ sub python_package {
    say "[INFO] Installing $package_name";
    my $status = chdir "$package_name";
    if ( $status == 0 ) {
        say "[ERROR] folder $package_name is not present";
        die "[ERROR] folder $package_name is not present";
    }
    my $output = system("${python} setup.py install");
    if ( $? != 0 ) {
        croak "[ERROR] $package_name exited with different exit code than 0!";
        die "[ERROR] $package_name exited with different exit code than 0!";
    }
    $status = chdir '..';
    if ( $status == 0 ) {
        croak "[FATAL] Could not return to the working directory";
        die "[ERROR] Could not return to the working directory";
    }
    return;
}
@@ -279,21 +274,20 @@ my ($printer_name) = @ARGV;
# Check for smbclient
my $output = `which smbclient >/dev/null 2>/dev/null`;
if ( $? != 0 ) {
    say "Samba client seems not to be installed. (smbclinet)";
    exit 1;
    die "[ERROR] Samba client seems not to be installed. (smbclinet)";
}

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

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

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

#TA5007ci requires python2 reportlab and PyPDF2
if ( $model eq "TA5007ci" ) {
@@ -309,7 +303,7 @@ foreach ( $models->{$model}->{'filters'} ) {

install_printer("$printer_name");

say "Installation is completed";
say "You may alter the printer settings in cups interface.";
say "[INFO] Installation is completed";
say "You may alter the printer settings in cups interface.";    # NOTE usefull?

# hp_laserjet_600($printer_name);