"Fossies" - the Fresh Open Source Software Archive

Member "foomatic-db-engine-4.0-20221101/foomatic-kitload.in" (1 Nov 2022, 3239 Bytes) of package /linux/misc/foomatic-db-engine-4.0-20221101.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!@PERL@
    2 
    3 use Foomatic::Defaults;
    4 
    5 die "No \$libdir defined in Foomatic::Defaults!?"
    6     unless $libdir;
    7 
    8 use Getopt::Std;
    9 getopts("d:hk:lf");
   10 help() if $opt_h;
   11 
   12 list() if $opt_l;
   13 
   14 if (! -d $opt_k) {
   15     warn "No such directory `$opt_k'\n";
   16     help();
   17 }
   18 
   19 # Only overwrite existing files if the "-f" ("force") flag is set.
   20 my $dontoverwrite;
   21 if ($opt_f) {
   22     $dontoverwrite = "";
   23 } else {
   24     $dontoverwrite = "k";
   25 }
   26 
   27 # OK, now sanity check and import
   28 my $destdir = $opt_d;
   29 my $dir = $opt_k;
   30 if (!(-d "$dir/printer" or -d "$dir/driver" or -d "$dir/opt")) {
   31     die "No printer, driver, and/or opt directory in $dir; invalid kit?\n";
   32 }
   33 
   34 die "That's the library directory!\n"
   35     if ($dir =~ m"$destdir$libdir/db/source/?");
   36 
   37 open FILES, "find $dir -type f -print |" 
   38     or die "Cannot run find!?";
   39 while (<FILES>) {
   40     chomp;
   41     next if (m/^CVS$/);
   42     die "Non-xml file $_!\n"
   43 	if (! m/\.xml$/);
   44 }
   45 close FILES or die "Cannot close pipe from find!";
   46 
   47 # OK, we think it's valid now.
   48 
   49 die "Foomatic library directory '$destdir$libdir/db' is not writable!\n"
   50     if (! (-d "$destdir$libdir/db" and -w "$destdir$libdir/db"));
   51 
   52 # Make "tar" giving english output
   53 $ENV{'LC_ALL'} = "C";
   54 $ENV{'LANG'} = "C";
   55 
   56 # Copy the files
   57 my $retval = system("( cd $dir ; tar cf - --exclude CVS . ) | tar xv${dontoverwrite}Cf $destdir$libdir/db/source - 2> $destdir$libdir/kitload2.log | tee $destdir$libdir/kitload.log");
   58 #$retval = $retval / 256;
   59 #if ($retval) {
   60 #    die "Error copying files to $destdir$libdir/db/source: $?";
   61 #}
   62 
   63 # Clean up log file from files which could not be copied.
   64 open STDOUTLOG, "< $destdir$libdir/kitload.log" or
   65     die "Cannot read $destdir$libdir/kitload.log!";
   66 my @stdoutlog = <STDOUTLOG>;
   67 close STDOUTLOG;
   68 open STDERRLOG, "< $destdir$libdir/kitload2.log" or
   69     die "Cannot read $destdir$libdir/kitload2.log!";
   70 my $all_ok = 1;
   71 while ($eline = <STDERRLOG>) {
   72     for $oline (@stdoutlog) {
   73 	$choline = $oline;
   74 	chomp($choline);
   75 	next if ($choline !~ m!.xml$!);
   76 	if ($eline =~ m!$choline!) {
   77 	    $oline = "";
   78 	    $all_ok = 0;
   79 	}
   80     }
   81 }
   82 my $newlog = join("", @stdoutlog);
   83 close STDERRLOG;
   84 if ($newlog !~ m!.xml$!m) {
   85     show_errors();
   86     warn "\nNo file written into the database, probably this kit is already installed\nor it is empty!\n";
   87     unlink "$destdir$libdir/kitload.log" or
   88 	die "Cannot delete $destdir$libdir/kitload.log!";
   89 } else {
   90     if (!$all_ok) {
   91 	show_errors();
   92 	warn "\nSome files of the kit could not be written! The list of actually written\nfiles you find in $destdir$libdir/kitload.log.\n";
   93     } else {
   94 	print "\nKit successfully installed! The list of written files you find in\n$destdir$libdir/kitload.log.\n";
   95     }
   96     open STDOUTLOG, "> $destdir$libdir/kitload.log" or
   97 	die "Cannot write $destdir$libdir/kitload.log!";
   98     print STDOUTLOG $newlog;
   99     close STDOUTLOG;
  100 }
  101 unlink "$destdir$libdir/kitload2.log" or
  102     die "Cannot delete $destdir$libdir/kitload2.log!";
  103 
  104 exit 0;
  105 
  106 sub list {
  107     print STDOUT "$libdir/db/source\n";
  108     exit(0);
  109 }
  110 
  111 sub help {
  112     print STDERR "Usage: foomatic-kitload -k kit-dir [-d destination prefix] [-l] [-f]\n";
  113     exit(0);
  114 }
  115 
  116 sub show_errors {
  117     warn "\nError messages of the copying process:\n\n";
  118     print STDERR `cat $destdir$libdir/kitload2.log`;
  119 }