view src/pkg-files.pl @ 35:4823f88ea3b6

add -0 option to pkg-files.
author Robert McIntyre <rlm@mit.edu>
date Sun, 10 Feb 2013 05:58:58 -0500
parents 6422228dfea7
children
line wrap: on
line source
1 #!/usr/bin/perl
2 use File::stat;
4 $print0 = 0;
6 if ($ARGV[0] eq "--help"){
7 print <<"HERE";
9 pkg-examine -- print package contents.
11 usage:
12 pkg-examine -0 <package>
14 Prints the files which belong to the package user
15 <package>.
17 If the -0 option is given, prints all files belonging
18 to <package> separated by null characters, as in the
19 "-print0" option of find.
21 Written by Robert McIntyre. This software is free
22 software and is released to the public domain.
24 HERE
25 exit 0;
26 }
28 $" = " ";
30 if ($ARGV[0] eq "-0"){
31 $print0 = 1;
32 $pkg_name = $ARGV[1];
33 }
34 else {
35 $pkg_name = $ARGV[0];
36 }
41 `id -g $pkg_name 2>/dev/null`;
42 if (($pkg_name eq "") || $?){
43 print "No group named $pkg_name.\n";
44 exit 0;
45 }
47 $file_str = `find /usr /opt /etc -group $pkg_name -print0`;
48 if ($print0){
49 print $file_str;
50 exit 0;
51 }
53 @files = split(/\0/, $file_str);
56 print "All files owned by this package:\n";
57 foreach (@files){print " $_\n";}
59 print "SetUID/SetGID files:\n";
60 foreach $file(@files){
62 $sb = stat($file);
63 $mode = $sb->mode & 07777;
64 if ($mode & 07000){
65 printf "%s, %04o\n", $file, $mode;
66 }
67 }