home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / usr / bin / dpkg-distaddfile < prev    next >
Encoding:
Text File  |  2001-09-18  |  1.9 KB  |  68 lines

  1. #! /usr/bin/perl
  2.  
  3. my $dpkglibdir, $version;
  4.  
  5. BEGIN { 
  6.     $dpkglibdir="/usr/share/dpkg";
  7.     $version=""; # This line modified by Makefile
  8.     push (@INC, $dpkglibdir); 
  9. }
  10.  
  11. use POSIX;
  12. use POSIX qw(:errno_h :signal_h);
  13.  
  14. require 'controllib.pl';
  15.  
  16. $fileslistfile= 'debian/files';
  17.  
  18. sub usageversion {
  19.     print STDERR
  20. "Debian GNU/Linux dpkg-distaddfile $version.  Copyright (C) 1996
  21. Ian Jackson.  This is free software; see the GNU General Public Licence
  22. version 2 or later for copying conditions.  There is NO warranty.
  23.  
  24. Usage:
  25.   dpkg-distaddfile <filename> <section> <priority>
  26. Options:  -f<fileslistfile>      write files here instead of debian/files
  27.           -h                     print this message
  28. ";
  29. }
  30.  
  31. while (@ARGV && $ARGV[0] =~ m/^-/) {
  32.     $_=shift(@ARGV);
  33.     if (m/^-f/) {
  34.         $fileslistfile= $';
  35.     } elsif (m/^-h$/) {
  36.         &usageversion; exit(0);
  37.     } elsif (m/^--$/) {
  38.         last;
  39.     } else {
  40.         &usageerr("unknown option $_");
  41.     }
  42. }
  43.  
  44. @ARGV==3 || &usageerr("need exactly a filename, section and priority");
  45. ($file,$section,$priority)= @ARGV;
  46.  
  47. ($file =~ m/\s/ || $section =~ m/\s/ || $priority =~ m/\s/) &&
  48.     &error("filename, section and priority may contain no whitespace");
  49.  
  50. $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
  51. open(Y,"> $fileslistfile.new") || &syserr("open new files list file");
  52. my (@fowner) = &getfowner ();
  53. chown (@fowner, "$fileslistfile.new")
  54.     || &syserr ("chown new files list file");
  55. if (open(X,"< $fileslistfile")) {
  56.     while (<X>) {
  57.         s/\n$//;
  58.         next if m/^(\S+) / && $1 eq $file;
  59.         print(Y "$_\n") || &syserr("copy old entry to new files list file");
  60.     }
  61. } elsif ($! != ENOENT) {
  62.     &syserr("read old files list file");
  63. }
  64. print(Y "$file $section $priority\n")
  65.     || &syserr("write new entry to new files list file");
  66. close(Y) || &syserr("close new files list file");
  67. rename("$fileslistfile.new",$fileslistfile) || &syserr("install new files list file");
  68.