#!/usr/bin/perl
#
# D. Bortolotti 15/2/2006

use Socket;
use Sys::Hostname;

################ Configuration name files
$lpoptions      = "/etc/cups/lpoptions";


################ Check Ip and Subnet address
$host   = hostname();
$addr   = inet_ntoa(scalar(gethostbyname($host)) || 'localhost');
$addr   =~ m/(\d+)\.(\d+)\.(\d+)/;
$subnet = $3;
if ($subnet eq '10' || $subnet eq '12' || $subnet eq '1')  {
    $area = "i";
    $defaultprinter = "phaseribn";
    }
elsif ($subnet eq '11' || $subnet eq '102' || $subnet eq '2')  {
    $area = "m";
    $defaultprinter = "phaser$area";
}
else {
    print "Errore nella configurazione di rete: $host, $addr\n";
    print "Sistema il file /etc/hosts:\ndistingui la riga di 127.0.0.1 da quella del nome-numero di rete\n";
    exit;
}

# Create a new lpoptions file 
open(OPTIONS,">$lpoptions");
print OPTIONS "Default $defaultprinter\n";
print OPTIONS <<EOF;
Dest phaseribn-two number-up=2
Dest phaseribn-simplex sides=one-sided
Dest phaseric-two number-up=2
Dest lpscci-two number-up=2
Dest phaseri-two number-up=2
Dest lps2-two number-up=2
Dest lpstg-two number-up=2
Dest phaserm-two number-up=2
Dest phaserm-simplex sides=one-sided
Dest phasermc-two number-up=2
EOF
close(OPTIONS);
