home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / genhdlist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-23  |  3.3 KB  |  128 lines

  1. #include <alloca.h>
  2. #include <ctype.h>
  3. #include <dirent.h>
  4. #include <errno.h>
  5. #include <fcntl.h>
  6. #include <rpmlib.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <unistd.h>
  12.  
  13. #define FILENAME_TAG 1000000
  14.  
  15. int tags[] =  { RPMTAG_NAME, RPMTAG_VERSION, RPMTAG_RELEASE, RPMTAG_SERIAL,
  16.         RPMTAG_FILENAMES, RPMTAG_FILESIZES, RPMTAG_GROUP,
  17.         RPMTAG_REQUIREFLAGS, RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION,
  18.         RPMTAG_DESCRIPTION, RPMTAG_SUMMARY, RPMTAG_PROVIDES,
  19.         RPMTAG_SIZE, RPMTAG_OBSOLETES };
  20. int numTags = sizeof(tags) / sizeof(int);
  21.  
  22. int main(int argc, char ** argv) {
  23.     char buf[300];
  24.     DIR * dir;
  25.     int outfd;
  26.     struct dirent * ent;
  27.     int fd, rc, isSource;
  28.     Header h;
  29.     int count, type;
  30.     int i;
  31.     void * ptr;
  32.  
  33.     if (argc != 2) {
  34.     fprintf(stderr, "usage: genhdlist <dir>\n");
  35.     exit(1);
  36.     }
  37.  
  38.     strcpy(buf, argv[1]);
  39.     strcat(buf, "/RedHat/RPMS");
  40.  
  41.     dir = opendir(buf);
  42.     if (!dir) {
  43.     fprintf(stderr,"error opening directory %s: %s\n", buf,
  44.         strerror(errno));
  45.     return 1;
  46.     }
  47.     chdir(buf);
  48.  
  49.     strcpy(buf, argv[1]);
  50.     strcat(buf, "/RedHat/base/hdlist");
  51.     
  52.     outfd = open(buf, O_WRONLY | O_TRUNC | O_CREAT, 0644);
  53.     if (outfd < 0) {
  54.     fprintf(stderr,"error creating file %s: %s\n", buf, strerror(errno));
  55.     return 1;
  56.     }
  57.  
  58.     errno = 0;
  59.     ent = readdir(dir);
  60.     if (errno) {
  61.     perror("readdir");
  62.     return 1;
  63.     }
  64.  
  65.     while (ent) {
  66.     if (!(ent->d_name[0] == '.' && (ent->d_name[1] == '\0' || 
  67.         ((ent->d_name[1] == '.') && (ent->d_name[2] == '\0'))))) {
  68.         fd = open(ent->d_name, O_RDONLY);
  69.  
  70.         if (fd < 0) {
  71.         perror("open");
  72.         exit(1);
  73.         }
  74.  
  75.         rc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL);
  76.  
  77.         headerRemoveEntry(h, RPMTAG_POSTIN);
  78.         headerRemoveEntry(h, RPMTAG_POSTUN);
  79.         headerRemoveEntry(h, RPMTAG_PREIN);
  80.         headerRemoveEntry(h, RPMTAG_PREUN);
  81.         headerRemoveEntry(h, RPMTAG_FILEMD5S);
  82.         headerRemoveEntry(h, RPMTAG_FILELINKTOS);
  83.         headerRemoveEntry(h, RPMTAG_FILEUSERNAME);
  84.         headerRemoveEntry(h, RPMTAG_FILEGROUPNAME);
  85.         headerRemoveEntry(h, RPMTAG_FILEVERIFYFLAGS);
  86.         headerRemoveEntry(h, RPMTAG_FILESIZES);
  87.         headerRemoveEntry(h, RPMTAG_FILERDEVS);
  88.         headerRemoveEntry(h, RPMTAG_FILEMTIMES);
  89.         headerRemoveEntry(h, RPMTAG_FILEDEVICES);
  90.         headerRemoveEntry(h, RPMTAG_FILEINODES);
  91.         headerRemoveEntry(h, RPMTAG_FILELANGS);
  92.         headerRemoveEntry(h, RPMTAG_FILEFLAGS);
  93.         headerRemoveEntry(h, RPMTAG_TRIGGERSCRIPTS);
  94.         headerRemoveEntry(h, RPMTAG_TRIGGERVERSION);
  95.         headerRemoveEntry(h, RPMTAG_TRIGGERFLAGS);
  96.         headerRemoveEntry(h, RPMTAG_TRIGGERNAME);
  97.         headerRemoveEntry(h, RPMTAG_CHANGELOGTIME);
  98.         headerRemoveEntry(h, RPMTAG_CHANGELOGNAME);
  99.         headerRemoveEntry(h, RPMTAG_CHANGELOGTEXT);
  100.         headerRemoveEntry(h, RPMTAG_ICON);
  101.         headerRemoveEntry(h, RPMTAG_GIF);
  102.         headerRemoveEntry(h, RPMTAG_VENDOR);
  103.         headerRemoveEntry(h, RPMTAG_EXCLUDE);
  104.         headerRemoveEntry(h, RPMTAG_EXCLUSIVE);
  105.         headerRemoveEntry(h, RPMTAG_DISTRIBUTION);
  106.         headerRemoveEntry(h, RPMTAG_VERIFYSCRIPT);
  107.  
  108.         headerAddEntry(h, FILENAME_TAG, RPM_STRING_TYPE, ent->d_name, 1);
  109.  
  110.         headerWrite(outfd, h, HEADER_MAGIC_YES);
  111.         headerFree(h);
  112.         close(fd);
  113.     }
  114.  
  115.     errno = 0;
  116.     ent = readdir(dir);
  117.     if (errno) {
  118.         perror("readdir");
  119.         return 1;
  120.     }
  121.     } 
  122.  
  123.     closedir(dir);
  124.     close(outfd);
  125.  
  126.     return 0;
  127. }
  128.