inventory.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env sh
  2. #
  3. # inventory.sh
  4. #
  5. # Originally written by Ben Lindstrom, modified by Darren Tucker to use perl
  6. # This file is placed into the public domain.
  7. #
  8. # This will produce an AIX package inventory file, which looks like:
  9. #
  10. # /usr/local/bin:
  11. # class=apply,inventory,openssh
  12. # owner=root
  13. # group=system
  14. # mode=755
  15. # type=DIRECTORY
  16. # /usr/local/bin/slogin:
  17. # class=apply,inventory,openssh
  18. # owner=root
  19. # group=system
  20. # mode=777
  21. # type=SYMLINK
  22. # target=ssh
  23. # /usr/local/share/Ssh.bin:
  24. # class=apply,inventory,openssh
  25. # owner=root
  26. # group=system
  27. # mode=644
  28. # type=FILE
  29. # size=VOLATILE
  30. # checksum=VOLATILE
  31. find . ! -name . -print | perl -ne '{
  32. chomp;
  33. if ( -l $_ ) {
  34. ($dev,$ino,$mod,$nl,$uid,$gid,$rdev,$sz,$at,$mt,$ct,$bsz,$blk)=lstat;
  35. } else {
  36. ($dev,$ino,$mod,$nl,$uid,$gid,$rdev,$sz,$at,$mt,$ct,$bsz,$blk)=stat;
  37. }
  38. # Start to display inventory information
  39. $name = $_;
  40. $name =~ s|^.||; # Strip leading dot from path
  41. print "$name:\n";
  42. print "\tclass=apply,inventory,openssh\n";
  43. print "\towner=root\n";
  44. print "\tgroup=system\n";
  45. printf "\tmode=%lo\n", $mod & 07777; # Mask perm bits
  46. if ( -l $_ ) {
  47. # Entry is SymLink
  48. print "\ttype=SYMLINK\n";
  49. printf "\ttarget=%s\n", readlink($_);
  50. } elsif ( -f $_ ) {
  51. # Entry is File
  52. print "\ttype=FILE\n";
  53. print "\tsize=$sz\n";
  54. print "\tchecksum=VOLATILE\n";
  55. } elsif ( -d $_ ) {
  56. # Entry is Directory
  57. print "\ttype=DIRECTORY\n";
  58. }
  59. }'