forked from michaelrsweet/epm
-
Notifications
You must be signed in to change notification settings - Fork 8
/
aix.c
853 lines (670 loc) · 26.6 KB
/
aix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
/*
* AIX package gateway for the ESP Package Manager (EPM).
*
* Copyright 2020 by Jim Jagielski
* Copyright 1999-2020 by Michael R Sweet
* Copyright 1999-2010 by Easy Software Products.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Include necessary headers...
*/
#include "epm.h"
/*
* Directory information...
*/
typedef struct {
char dst[1024]; /* Output directory */
int blocks; /* Size of files in this directory */
} aixdir_t;
/*
* Local functions...
*/
static int aix_addfile(int type, const char *src, const char *dst, int num_dirs,
aixdir_t **dirs);
static void aix_fileset(FILE *fp, const char *prodname, dist_t *dist,
const char *subpackage);
static char *aix_version(const char *version);
static int write_liblpp(const char *prodname, const char *directory, dist_t *dist,
int root, const char *subpackage);
/*
* Local globals...
*/
static const char *files[] = /* Control files... */
{"al", "cfgfiles", "copyright", "inventory",
"post_i", "pre_i", "unpost_i", "unpre_i"};
/*
* 'make_aix()' - Make an AIX software distribution package.
*/
int /* O - 0 = success, 1 = fail */
make_aix(const char *prodname, /* I - Product short name */
const char *directory, /* I - Directory for distribution files */
const char *platname, /* I - Platform name */
dist_t *dist, /* I - Distribution information */
struct utsname *platform) /* I - Platform information */
{
int i; /* Looping var */
FILE *fp; /* Control file */
char name[1024], /* Full product name */
filename[1024], /* Destination filename */
current[1024]; /* Current directory */
file_t *file; /* Current distribution file */
struct passwd *pwd; /* Pointer to user record */
struct group *grp; /* Pointer to group record */
const char *runlevels; /* Run levels */
REF(platform);
if (Verbosity)
puts("Creating AIX distribution...");
if (dist->release[0]) {
if (platname[0])
snprintf(name, sizeof(name), "%s-%s-%s-%s", prodname, dist->version,
dist->release, platname);
else
snprintf(name, sizeof(name), "%s-%s-%s", prodname, dist->version,
dist->release);
} else if (platname[0])
snprintf(name, sizeof(name), "%s-%s-%s", prodname, dist->version, platname);
else
snprintf(name, sizeof(name), "%s-%s", prodname, dist->version);
getcwd(current, sizeof(current));
/*
* Write the lpp_name file for installp...
*/
if (Verbosity)
puts("Creating lpp_name file...");
snprintf(filename, sizeof(filename), "%s/%s", directory, prodname);
make_directory(filename, 0755, 0, 0);
snprintf(filename, sizeof(filename), "%s/%s/lpp_name", directory, prodname);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create lpp_name file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
fprintf(fp, "4 R I %s {\n", prodname);
aix_fileset(fp, prodname, dist, NULL);
for (i = 0; i < dist->num_subpackages; i++)
aix_fileset(fp, prodname, dist, dist->subpackages[i]);
fputs("}\n", fp);
fclose(fp);
/*
* Write the root partition liblpp.a file...
*/
write_liblpp(prodname, directory, dist, 1, NULL);
for (i = 0; i < dist->num_subpackages; i++)
write_liblpp(prodname, directory, dist, 1, dist->subpackages[i]);
/*
* Write the usr partition liblpp.a file...
*/
write_liblpp(prodname, directory, dist, 0, NULL);
for (i = 0; i < dist->num_subpackages; i++)
write_liblpp(prodname, directory, dist, 0, dist->subpackages[i]);
/*
* Copy the files over...
*/
if (Verbosity)
puts("Copying temporary distribution files...");
for (i = dist->num_files, file = dist->files; i > 0; i--, file++) {
/*
* Find the username and groupname IDs...
*/
pwd = getpwnam(file->user);
grp = getgrnam(file->group);
endpwent();
endgrent();
/*
* Copy the file or make the directory or make the symlink as needed...
*/
switch (tolower(file->type)) {
case 'c':
case 'f':
if (!strncmp(file->dst, "/export/", 8) || !strncmp(file->dst, "/opt/", 5) ||
!strncmp(file->dst, "/usr/", 5))
snprintf(filename, sizeof(filename), "%s/%s%s", directory, prodname,
file->dst);
else
snprintf(filename, sizeof(filename), "%s/%s/usr/lpp/%s/inst_root%s",
directory, prodname, prodname, file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0,
grp ? grp->gr_gid : 0))
return (1);
break;
case 'i':
for (runlevels = get_runlevels(file, "2"); isdigit(*runlevels & 255);
runlevels++) {
snprintf(filename, sizeof(filename),
"%s/%s/usr/lpp/%s/inst_root/etc/rc.d/rc%c.d/S%02d%s", directory,
prodname, prodname, *runlevels, get_start(file, 99), file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0,
grp ? grp->gr_gid : 0))
return (1);
snprintf(filename, sizeof(filename),
"%s/%s/usr/lpp/%s/inst_root/etc/rc.d/rc%c.d/K%02d%s", directory,
prodname, prodname, *runlevels, get_stop(file, 0), file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
if (copy_file(filename, file->src, file->mode, pwd ? pwd->pw_uid : 0,
grp ? grp->gr_gid : 0))
return (1);
}
break;
case 'd':
if (!strcmp(file->dst, "/export") || !strncmp(file->dst, "/export/", 8) ||
!strcmp(file->dst, "/opt") || !strncmp(file->dst, "/opt/", 5) ||
!strcmp(file->dst, "/usr") || !strncmp(file->dst, "/usr/", 5))
snprintf(filename, sizeof(filename), "%s/%s%s", directory, prodname,
file->dst);
else
snprintf(filename, sizeof(filename), "%s/%s/usr/lpp/%s/inst_root%s",
directory, prodname, prodname, file->dst);
if (Verbosity > 1)
printf("Directory %s...\n", filename);
make_directory(filename, file->mode, pwd ? pwd->pw_uid : 0,
grp ? grp->gr_gid : 0);
break;
case 'l':
if (!strncmp(file->dst, "/export/", 8) || !strncmp(file->dst, "/opt/", 5) ||
!strncmp(file->dst, "/usr/", 5))
snprintf(filename, sizeof(filename), "%s/%s%s", directory, prodname,
file->dst);
else
snprintf(filename, sizeof(filename), "%s/%s/usr/lpp/%s/inst_root%s",
directory, prodname, prodname, file->dst);
if (Verbosity > 1)
printf("%s -> %s...\n", file->src, filename);
make_link(filename, file->src);
break;
}
}
/*
* Build the distribution from the spec file...
*/
if (Verbosity)
puts("Building AIX binary distribution...");
snprintf(filename, sizeof(filename), "%s/%s", directory, prodname);
if (run_command(filename, "sh -c \'find . -print | backup -i -f ../%s.bff -q %s\'",
prodname, Verbosity ? "-v" : ""))
return (1);
/*
* Remove temporary files...
*/
if (!KeepFiles) {
if (Verbosity)
puts("Removing temporary distribution files...");
snprintf(filename, sizeof(filename), "%s/%s", directory, prodname);
unlink_directory(filename);
for (i = 0; i < (sizeof(files) / sizeof(files[0])); i++) {
snprintf(filename, sizeof(filename), "%s/%s.%s", directory, prodname,
files[i]);
unlink(filename);
}
snprintf(filename, sizeof(filename), "%s/lpp.README", directory);
unlink(filename);
}
return (0);
}
/*
* 'aix_addfile()' - Add a file to the AIX directory list...
*/
static int /* O - New number dirs */
aix_addfile(int type, /* I - Filetype */
const char *src, /* I - Source path */
const char *dst, /* I - Destination path */
int num_dirs, /* I - Number of directories */
aixdir_t **dirs) /* IO - Directories */
{
int i, j; /* Looping vars */
int blocks; /* Blocks to add... */
struct stat fileinfo; /* File information */
aixdir_t *temp; /* Temporary pointer */
char dstpath[1024], /* Destination path */
*dstptr; /* Pointer into destination */
/*
* Determine the destination path and block size...
*/
strlcpy(dstpath, dst, sizeof(dstpath));
if (type == 'd') {
blocks = 1;
dstptr = dstpath + strlen(dstpath) - 1;
} else {
dstptr = strrchr(dstpath, '/');
if (type == 'l')
blocks = 1;
else if (!stat(src, &fileinfo))
blocks = (int)((fileinfo.st_size + 511) / 512);
else
blocks = 0;
}
if (dstptr && *dstptr == '/' && dstptr > dstpath)
*dstptr = '\0';
/*
* Now see if the destination path is in the array...
*/
temp = *dirs;
for (i = 0; i < num_dirs; i++)
if ((j = strcmp(temp[i].dst, dstpath)) == 0) {
temp[i].blocks += blocks;
return (num_dirs);
} else if (j > 0)
break;
/*
* Not in the list; allocate a new one...
*/
if (num_dirs == 0)
temp = malloc(sizeof(aixdir_t));
else
temp = realloc(*dirs, (num_dirs + 1) * sizeof(aixdir_t));
if (!temp)
return (num_dirs);
*dirs = temp;
temp += i;
if (i < num_dirs)
memmove(temp + 1, temp, (num_dirs - i) * sizeof(aixdir_t));
strlcpy(temp->dst, dstpath, sizeof(temp->dst));
temp->blocks = blocks;
return (num_dirs + 1);
}
/*
* 'aix_fileset()' - Write a subpackage description...
*/
static void aix_fileset(FILE *fp, /* I - File to write to */
const char *prodname, /* I - Product name */
dist_t *dist, /* I - Distribution */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
depend_t *d; /* Current dependency */
file_t *file; /* Current distribution file */
int num_dirs; /* Number of directories */
aixdir_t *dirs; /* Directories */
/*
* Start fileset definition...
*/
if (subpackage)
fprintf(fp, "%s.%s", prodname, subpackage);
else
fprintf(fp, "%s", prodname);
fprintf(fp, " %s 01 N B x ", aix_version(dist->version));
if (subpackage) {
for (i = 0; i < dist->num_descriptions; i++) {
if (dist->descriptions[i].subpackage == subpackage) {
fprintf(fp, "%s\n", dist->descriptions[i].description);
break;
}
}
} else
fprintf(fp, "%s\n", dist->product);
/*
* Dependencies...
*/
fputs("[\n", fp);
for (i = dist->num_depends, d = dist->depends; i > 0; i--, d++)
if (d->type == DEPEND_REQUIRES && d->subpackage == subpackage &&
strcmp(d->product, "_self"))
fprintf(fp, "*prereq %s %s\n", d->product, aix_version(d->version[0]));
/*
* Installation sizes...
*/
fputs("%\n", fp);
num_dirs = 0;
dirs = NULL;
for (i = dist->num_files, file = dist->files; i > 0; i--, file++)
if (file->subpackage == subpackage)
num_dirs =
aix_addfile(tolower(file->type), file->src, file->dst, num_dirs, &dirs);
for (i = 0; i < num_dirs; i++)
fprintf(fp, "%s %d\n", dirs[i].dst, dirs[i].blocks);
if (num_dirs > 0)
free(dirs);
/*
* This package supercedes which others?
*/
fputs("%\n", fp);
for (i = dist->num_depends, d = dist->depends; i > 0; i--, d++)
if (d->type == DEPEND_REPLACES && d->subpackage == subpackage &&
strcmp(d->product, "_self"))
fprintf(fp, "%s %s", d->product, aix_version(d->version[0]));
/*
* Fix information is only used for updates (patches)...
*/
fputs("%\n", fp);
fputs("]\n", fp);
}
/*
* 'aix_version()' - Generate an AIX version number.
*/
static char * /* O - AIX version number */
aix_version(const char *version) /* I - EPM version number */
{
int verparts[4]; /* Version number parts */
static char aix[255]; /* AIX version number string */
/*
* AIX requires a four-part version number (M.m.p.r)...
*/
memset(verparts, 0, sizeof(verparts));
sscanf(version, "%d.%d.%d.%d", verparts + 0, verparts + 1, verparts + 2,
verparts + 3);
snprintf(aix, sizeof(aix), "%d.%d.%d.%d", verparts[0], verparts[1], verparts[2],
verparts[3]);
return (aix);
}
/*
* 'write_liblpp()' - Create the liblpp.a file for the root or /usr parts.
*/
static int /* O - 0 = success, 1 = fail */
write_liblpp(const char *prodname, /* I - Product short name */
const char *directory, /* I - Directory for distribution files */
dist_t *dist, /* I - Distribution information */
int root, /* I - Root partition? */
const char *subpackage) /* I - Subpackage */
{
int i; /* Looping var */
FILE *fp; /* Control file */
char filename[1024], /* Destination filename */
prodfull[1024]; /* Full product name */
struct stat fileinfo; /* File information */
command_t *c; /* Current command */
file_t *file; /* Current distribution file */
int configcount; /* Number of config files */
int shared_file; /* Shared file? */
const char *runlevels; /* Run levels */
/*
* Progress info...
*/
if (subpackage)
snprintf(prodfull, sizeof(prodfull), "%s.%s", prodname, subpackage);
else
strlcpy(prodfull, prodname, sizeof(prodfull));
if (Verbosity)
printf("Updating %s partition liblpp.a file for %s...\n",
root ? "root" : "shared", prodfull);
/*
* Write the product.al file for installp...
*/
if (Verbosity > 1)
puts(" Creating .al file...");
snprintf(filename, sizeof(filename), "%s/%s.al", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .al file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
for (i = dist->num_files, file = dist->files; i > 0; i--, file++)
if (file->subpackage == subpackage)
switch (tolower(file->type)) {
case 'i':
for (runlevels = get_runlevels(file, "2"); isdigit(*runlevels & 255);
runlevels++) {
if (root)
putc('.', fp);
else
qprintf(fp, "./usr/lpp/%s/inst_root", prodfull);
if (*runlevels == '0')
qprintf(fp, "/etc/rc.d/rc0.d/K%02d%s\n", get_stop(file, 0),
file->dst);
else
qprintf(fp, "/etc/rc.d/rc%c.d/S%02d%s\n", *runlevels,
get_start(file, 99), file->dst);
}
break;
default:
shared_file =
!(strcmp(file->dst, "/usr") && strncmp(file->dst, "/usr/", 5) &&
strcmp(file->dst, "/opt") && strncmp(file->dst, "/opt/", 5));
/*
* Put file in root or share .al file as appropriate
*/
if ((shared_file && !root) || (!shared_file && root))
qprintf(fp, ".%s\n", file->dst);
/*
* Put any root file in the share .al so it will be extracted
* to /usr/lpp/<prodfull>/inst_root directory. I have no
* idea if this is really the way to do it but it seems to
* work...
*/
if (!shared_file && !root)
qprintf(fp, "./usr/lpp/%s/inst_root%s\n", prodfull, file->dst);
break;
}
fclose(fp);
/*
* Write the product.cfgfiles file for installp...
*/
if (Verbosity > 1)
puts(" Creating .cfgfiles file...");
snprintf(filename, sizeof(filename), "%s/%s.cfgfiles", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .cfgfiles file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
configcount = 0;
for (i = dist->num_files, file = dist->files; i > 0; i--, file++)
if (tolower(file->type) == 'c' && file->subpackage == subpackage &&
(strcmp(file->dst, "/usr") || strncmp(file->dst, "/usr/", 5) ||
strcmp(file->dst, "/opt") || strncmp(file->dst, "/opt/", 5)) == root) {
qprintf(fp, ".%s hold_new\n", file->dst);
configcount++;
}
fclose(fp);
/*
* Write the product.copyright file for installp...
*/
if (Verbosity > 1)
puts(" Creating .copyright file...");
snprintf(filename, sizeof(filename), "%s/%s.copyright", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .copyright file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
fprintf(fp, "%s, %s\n%s\n%s\n", dist->product, aix_version(dist->version),
dist->vendor, dist->copyright);
fclose(fp);
if (root) {
/*
* Write the product.pre_i file for installp...
*/
if (Verbosity > 1)
puts(" Creating .pre_i file...");
snprintf(filename, sizeof(filename), "%s/%s.pre_i", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .pre_i file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
fchmod(fileno(fp), 0755);
fputs("#!/bin/sh\n", fp);
fputs("# " EPM_VERSION "\n", fp);
for (c = dist->commands, i = dist->num_commands; i > 0; i--, c++)
if (c->type == COMMAND_PRE_INSTALL && c->subpackage == subpackage)
fprintf(fp, "%s\n", c->command);
fclose(fp);
/*
* Write the product.post_i file for installp...
*/
if (Verbosity > 1)
puts(" Creating .post_i file...");
snprintf(filename, sizeof(filename), "%s/%s.post_i", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .post_i file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
fchmod(fileno(fp), 0755);
fputs("#!/bin/sh\n", fp);
fputs("# " EPM_VERSION "\n", fp);
for (c = dist->commands, i = dist->num_commands; i > 0; i--, c++)
if (c->type == COMMAND_POST_INSTALL && c->subpackage == subpackage)
fprintf(fp, "%s\n", c->command);
fclose(fp);
/*
* Write the product.unpre_i file for installp...
*/
if (Verbosity > 1)
puts(" Creating .unpre_i file...");
snprintf(filename, sizeof(filename), "%s/%s.unpre_i", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .unpre_i file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
fchmod(fileno(fp), 0755);
fputs("#!/bin/sh\n", fp);
fputs("# " EPM_VERSION "\n", fp);
for (c = dist->commands, i = dist->num_commands; i > 0; i--, c++)
if (c->type == COMMAND_PRE_REMOVE && c->subpackage == subpackage)
fprintf(fp, "%s\n", c->command);
fclose(fp);
/*
* Write the product.unpost_i file for installp...
*/
if (Verbosity > 1)
puts(" Creating .unpost_i file...");
snprintf(filename, sizeof(filename), "%s/%s.unpost_i", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .unpost_i file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
fchmod(fileno(fp), 0755);
fputs("#!/bin/sh\n", fp);
fputs("# " EPM_VERSION "\n", fp);
for (c = dist->commands, i = dist->num_commands; i > 0; i--, c++)
if (c->type == COMMAND_POST_REMOVE && c->subpackage == subpackage)
fprintf(fp, "%s\n", c->command);
fclose(fp);
}
/*
* Write the product.inventory file for installp...
*/
if (Verbosity > 1)
puts(" Creating .inventory file...");
snprintf(filename, sizeof(filename), "%s/%s.inventory", directory, prodfull);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "epm: Unable to create .inventory file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
for (i = dist->num_files, file = dist->files; i > 0; i--, file++) {
if (file->subpackage != subpackage)
continue;
if (root) {
if (!strcmp(file->dst, "/usr") || !strncmp(file->dst, "/usr/", 5) ||
!strcmp(file->dst, "/opt") || !strncmp(file->dst, "/opt/", 5))
continue;
} else {
if (tolower(file->type) == 'c' ||
(strcmp(file->dst, "/usr") && strncmp(file->dst, "/usr/", 5) &&
strcmp(file->dst, "/opt") && strncmp(file->dst, "/opt/", 5)))
continue;
}
switch (tolower(file->type)) {
case 'i':
for (runlevels = get_runlevels(file, "2"); isdigit(*runlevels & 255);
runlevels++) {
if (*runlevels == '0')
qprintf(fp, "/etc/rc.d/rc0.d/K%02d%s:\n", get_stop(file, 0),
file->dst);
else
qprintf(fp, "/etc/rc.d/rc%c.d/S%02d%s:\n", *runlevels,
get_start(file, 99), file->dst);
fprintf(fp, " class=apply,inventory,%s\n", prodfull);
fputs(" type=FILE\n", fp);
if (!stat(file->src, &fileinfo))
fprintf(fp, " size=%d\n", (int)fileinfo.st_size);
fprintf(fp, " owner=%s\n", file->user);
fprintf(fp, " group=%s\n", file->group);
fprintf(fp, " mode=%04o\n", (unsigned)file->mode);
fputs("\n", fp);
}
break;
default:
qprintf(fp, "%s:\n", file->dst);
fprintf(fp, " class=apply,inventory,%s\n", prodfull);
switch (tolower(file->type)) {
case 'd':
fputs(" type=DIRECTORY\n", fp);
break;
case 'l':
fputs(" type=SYMLINK\n", fp);
qprintf(fp, " target=%s\n", file->src);
break;
case 'c':
fputs(" type=FILE\n", fp);
fputs(" size=VOLATILE\n", fp);
break;
default:
fputs(" type=FILE\n", fp);
if (!stat(file->src, &fileinfo))
fprintf(fp, " size=%ld\n", (long)fileinfo.st_size);
break;
}
fprintf(fp, " owner=%s\n", file->user);
fprintf(fp, " group=%s\n", file->group);
fprintf(fp, " mode=%04o\n", (unsigned)file->mode);
fputs("\n", fp);
break;
}
}
fclose(fp);
/*
* Write the lpp.README file...
*/
snprintf(filename, sizeof(filename), "%s/lpp.README", directory);
if (dist->license[0])
copy_file(filename, dist->license, 0644, 0, 0);
else if (dist->readme[0])
copy_file(filename, dist->readme, 0644, 0, 0);
else if ((fp = fopen(filename, "w")) != NULL)
fclose(fp);
else {
fprintf(stderr, "epm: Unable to create .README file \"%s\": %s\n", filename,
strerror(errno));
return (1);
}
/*
* Create the liblpp.a file...
*/
if (Verbosity > 1)
puts(" Creating liblpp.a archive...");
if (root) {
snprintf(filename, sizeof(filename), "%s/%s/usr/lpp/%s/inst_root", directory,
prodname, prodname);
make_directory(filename, 0755, 0, 0);
snprintf(filename, sizeof(filename), "%s/usr/lpp/%s/inst_root/liblpp.a", prodname,
prodname);
} else {
snprintf(filename, sizeof(filename), "%s/%s/usr/lpp/%s", directory, prodname,
prodname);
make_directory(filename, 0755, 0, 0);
snprintf(filename, sizeof(filename), "%s/usr/lpp/%s/liblpp.a", prodname,
prodname);
}
if (!subpackage)
if (run_command(directory, "ar rc %s lpp.README", filename))
return (1);
for (i = 0; i < (sizeof(files) / sizeof(files[0])); i++) {
if (i >= 4 && !root)
break;
if (i == 1 && !configcount)
continue;
if (run_command(directory, "ar rc %s %s.%s", filename, prodfull, files[i]))
return (1);
}
return (0);
}