-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpp.back.macos
1113 lines (1012 loc) · 37.4 KB
/
pp.back.macos
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
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Macintosh OS X backend
#
# References:
# https://medium.com/swlh/the-easiest-way-to-build-macos-installer-for-your-application-34a11dd08744
# https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Introduction.html
# https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/PackageMakerUserGuide/Introduction/Introduction.html
# The pkgbuild man page
#
# Obsolete references:
# http://mirror.informatimago.com/next/developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/index.html
# http://mirror.informatimago.com/next/developer.apple.com/releasenotes/DeveloperTools/Installer.html
# https://download.osxgnu.org/OSXPM/package
#
# PolyPackage builds Mac OS package bundles (i.e. foo.pkg directories)
# by default. This is different from the "flat packages" introduced in
# Mac OS 10.5. The pp_macos_pkg_type variable controls which type is built.
# See http://s.sudre.free.fr/Stuff/Ivanhoe/FLAT.html for flat package details.
# http://www.mactech.com/articles/mactech/Vol.26/26.02/TheFlatPackage/index.html
#
# For online update support, Apple keeps its 'softwareupdate' tool
# for apple use only. However, see https://code.google.com/p/update-engine/
: NOTES <<.
# creating a dmg file for publishing on the web
hdiutil create -srcfolder /path/foo foo.dmg
hdiutil internet-enable -yes /path/foo.dmg
# Layout for packages
<name>-<cpy>/component/<file>
<name>-<cpt>/extras/postinstall
<name>-<cpt>/extras/postupgrade
# /Developer/usr/bin/packagemaker (man packagemaker)
Make a bunch of packages, and then build a 'distribution'
which is only understood by macos>10.4
# Message files in the resource path used are
Welcome.{rtf,html,rtfd,txt} - limited text shown in Intro
ReadMe.{rtf,html,rtfd,txt} - scrollable/printable, after Intro
License.{rtf,html,rtfd,txt} - ditto, user must click 'Accept'
background.{jpg,tif,gif,pict,eps,pdf} 620x418 background image
# These scripts looked for in the resource path
InstallationCheck $pkgpath $defaultloc $targetvol
0:ok 32:warn 32+x:warn[1] 64:stop 96+x:stop[2]
VolumeCheck $volpath
0:ok 32:failure 32+x:failure[3]
preflight $pkgpath $targetloc $targetvol [priv]
preinstall $pkgpath $targetloc $targetvol [priv]
preupgrade $pkgpath $targetloc $targetvol [priv]
postinstall $pkgpath $targetloc $targetvol [priv]
postupgrade $pkgpath $targetloc $targetvol [priv]
postflight $pkgpath $targetloc $targetvol [priv]
0:ok else fail (for all scripts)
A detailed reason is deduced by finding an index x (16..31)
in the file InstallationCheck.strings or VolumeCheck.strings.
Scripts marked [priv] are executed with root privileges.
None of the [priv] scripts are used by metapackages.
# Default permissions
Permissions of existing directories should match those
of a clean install of the OS; typically root:admin 0775
New directories or files should be 0775 or 0664 with the
appropriate user:group.
Exceptions:
/etc root:admin 0755
/var root:admin 0755
<http://mirror.informatimago.com/next/developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/Concepts/sd_pkg_flags.html>
Info.plist = {
CFBundleGetInfoString: "1.2.3, One Identity LLC.",
CFBundleIdentifier: "com.quest.rc.openssh",
CFBundleShortVersionString: "1.2.3",
IFMajorVersion: 1,
IFMinorVersion: 2,
IFPkgFlagAllowBackRev: false,
IFPkgFlagAuthorizationAction: "AdminAuthorization",
IFPkgFlagDefaultLocation: "/",
IFPkgFlagFollowLinks: true,
IFPkgFlagInstallFat: false,
IFPkgFlagInstalledSize: <integer>, # this is added by packagemaker
IFPkgFlagIsRequired: false,
IFPkgFlagOverwritePermissions: false,
IFPkgFlagRelocatable: false,
IFPkgFlagRestartAction: "NoRestart",
IFPkgFlagRootVolumeOnly: false,
IFPkgFlagUpdateInstalledLanguages: false,
IFPkgFormatVersion= 0.10000000149011612,
IFRequirementDicts: [ {
Level = "requires",
SpecArgument = "/opt/quest/lib/libvas.4.2.0.dylib",
SpecType = "file",
TestObject = true,
TestOperator = "eq", } ]
}
Description.plist = {
IFPkgDescriptionDescription = "this is the description text",
IFPkgDescriptionTitle = "quest-openssh"
}
# Startup scripts
'launchd' is a kind of combined inetd and rc/init.d system.
<https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/DesigningDaemons.html>
Create a /Library/LaunchDaemons/$daemonname.plist file
Examples found in /System/Library/LaunchDaemons/
See manual page launchd.plist(5) for details:
{ Label: "com.quest.rc.foo", # required
Program: "/sbin/program",
ProgramArguments: [ "/sbin/program", "arg1", "arg2" ], # required
RunAtLoad: true,
WatchPaths: [ "/etc/crontab" ],
QueueDirectories: [ "/var/cron/tabs" ],
inetdCompatibility: { Wait: false }, # inetd-only
OnDemand: false, # recommended
SessionCreate: true,
UserName: "nobody",
InitGroups: true,
Sockets: { # inetd only
Listeners: {
SockServiceName: "ssh",
Bonjour: ["ssh", "sftp-ssh"], } },
Disabled: false,
StandardErrorPath: "/dev/null",
}
How to add a new user
dscl . -create /Users/$user
dscl . -create /Users/$user UserShell /bin/bash
dscl . -create /Users/$user RealName "$user"
dscl . -create /Users/$user UniqueID $uid
dscl . -create /Users/$user PrimaryGroupID $gid
dscl . -create /Users/$user NFSHomeDirectory /Users/$user
dscl . -passwd /Users/$user "$passwd"
mkdir /Users/$user
chown $uid.$gid /Users/$user
.
pp_platforms="$pp_platforms macos"
#@ pp_backend_macos_detect(uname_s): return true if matches uname on macos
pp_backend_macos_detect () {
[ x"$1" = x"Darwin" ]
}
#@ pp_backend_macos_init(): initialises platform variables for macos
pp_backend_macos_init () {
pp_macos_default_bundle_id_prefix="com.quest.rc."
pp_macos_bundle_id=
pp_macos_bundle_vendor=
pp_macos_bundle_version=
pp_macos_bundle_info_string=
pp_macos_pkg_type=bundle
pp_macos_pkg_background=
pp_macos_pkg_background_dark=
pp_macos_pkg_license=
pp_macos_pkg_readme=
pp_macos_pkg_welcome=
pp_macos_sudo=sudo
pp_macos_installer_plugin=
# OS X puts the library version *before* the .dylib extension
pp_shlib_suffix='*.dylib'
}
#@ pp_macos_plist(cmds...): emits plist xml fragments
pp_macos_plist () {
typeset in
in=""
while test $# -gt 0; do
case "$1" in
start-plist) cat <<-.; in=" "; shift ;;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
.
end-plist) echo "</plist>"; in=; shift;;
'[') echo "$in<array>"; in="$in "; shift;;
']') echo "$in</array>"; in="${in# }"; shift;;
'{') echo "<dict>"; in="$in "; shift;;
'}') echo "</dict>"; in="${in# }"; shift;;
key) shift; echo "$in<key>$1</key>"; shift;;
string) shift;
echo "$1" | sed -e 's/&/&/g;s/</\</g;s/>/\>/g;' \
-e 's/^/'"$in"'<string>/;s/$/<\/string>/';
shift;;
true) echo "$in<true/>"; shift;;
false) echo "$in<false/>"; shift;;
real) shift; echo "$in<real>$1</real>"; shift;;
integer) shift; echo "$in<integer>$1</integer>"; shift;;
date) shift; echo "$in<date>$1</date>"; shift;; # ISO 8601 format
data) shift; echo "$in<data>$1</data>"; shift;; # base64 encoded
*) pp_error "pp_macos_plist: bad argument '$1'"; shift;;
esac
done
}
#@ pp_macos_rewrite_cpio (filelists): filter a cpio stream changing uid/gid/mode
pp_macos_rewrite_cpio () {
typeset script
script=$pp_wrkdir/cpio-rewrite.pl
cat <<-'.' >$script
#!/usr/bin/perl
#
# Filter a cpio file, applying the user/group/mode specified in %files
#
# A CPIO header block has octal fields at the following offset/lengths:
# 0 6 magic
# 6 6 dev
# 12 6 ino
# 18 6 mode
# 24 6 uid
# 30 6 gid
# 36 6 nlink
# 42 6 rdev
# 48 11 mtime
# 59 6 namesize (including NUL terminator)
# 65 11 filesize
# 76 --
#
use strict;
use warnings;
no strict 'subs';
# set %uid, %gid, %mode based on %files
my (%uid, %gid, %mode, %users, %groups);
my %type_map = ( d => 0040000, f => 0100000, s => 0120000 );
while (<DATA>) {
my ($type,$mode,$uid,$gid,$flags,$name) =
m/^(.) (\S+) (\S+) (\S+) (\S+) (\S+)/;
$mode = $type eq "f" ? "0644" : "0755" if $mode eq "-";
$uid = 0 if $uid eq "-";
$gid = 0 if $gid eq "-";
if ($uid ne "=" and $uid =~ m/\D/) {
unless (exists $users{$uid}) {
my @pw = getpwnam($uid) or die "bad username '$uid'";
$users{$uid} = $pw[2];
}
$uid = $users{$uid};
}
if ($gid ne "=" and $gid =~ m/\D/) {
unless (exists $groups{$gid}) {
my @gr = getgrnam($gid) or die "bad group'$gid'";
$groups{$gid} = $gr[2];
}
$gid = $groups{$gid};
}
$name =~ s:/$:: if $type eq "d";
$name = ".".$name."\0";
$uid{$name} = sprintf("%06o",int($uid)) unless $uid eq "=";
$gid{$name} = sprintf("%06o",int($gid)) unless $gid eq "=";
$mode{$name} = sprintf("%06o",oct($mode)|$type_map{$type}) unless $mode eq "=";
}
undef %users;
undef %groups;
# parse the cpio file
my $hdrlen = 76;
while (read(STDIN, my $header, $hdrlen)) {
my ($name, $namesize, $filesize);
my $filepad = 0;
if ($header =~ m/^07070[12]/) {
# SVR4 ASCII format, convert to ODC
if ($hdrlen == 76) {
# Read in rest of header and update header len for SVR4
read(STDIN, $header, 110 - 76, 76);
$hdrlen = 110;
}
my $ino = hex(substr($header, 6, 8)) & 0x3ffff;
my $mode = hex(substr($header, 14, 8)) & 0x3ffff;
my $uid = hex(substr($header, 22, 8)) & 0x3ffff;
my $gid = hex(substr($header, 30, 8)) & 0x3ffff;
my $nlink = hex(substr($header, 38, 8)) & 0x3ffff;
my $mtime = hex(substr($header, 46, 8)) & 0xffffffff;
$filesize = hex(substr($header, 54, 8)) & 0xffffffff;
my $dev_maj = hex(substr($header, 62, 8));
my $dev_min = hex(substr($header, 70, 8));
my $dev = &makedev($dev_maj, $dev_min) & 0x3ffff;
my $rdev_maj = hex(substr($header, 78, 8));
my $rdev_min = hex(substr($header, 86, 8));
my $rdev = &makedev($rdev_maj, $rdev_min) & 0x3ffff;
$namesize = hex(substr($header, 94, 8)) & 0x3ffff;
read(STDIN, $name, $namesize);
# Header + name is padded to a multiple of 4 bytes
my $namepad = (($hdrlen + $namesize + 3) & 0xfffffffc) - ($hdrlen + $namesize);
read(STDIN, my $padding, $namepad) if ($namepad);
# File data is padded to be a multiple of 4 bytes
$filepad = (($filesize + 3) & 0xfffffffc) - $filesize;
my $new_header = sprintf("070707%06o%06o%06o%06o%06o%06o%06o%011o%06o%011o", $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime, $namesize, $filesize);
$header = $new_header;
} elsif ($header =~ m/^070707/) {
# POSIX Portable ASCII Format
$namesize = oct(substr($header, 59, 6));
$filesize = oct(substr($header, 65, 11));
read(STDIN, $name, $namesize);
} else {
die "bad magic";
}
# update uid, gid and mode (already in octal)
substr($header, 24, 6) = $uid{$name} if exists $uid{$name};
substr($header, 30, 6) = $gid{$name} if exists $gid{$name};
substr($header, 18, 6) = $mode{$name} if exists $mode{$name};
print($header, $name);
# check for trailer at EOF
last if $filesize == 0 && $name =~ /^TRAILER!!!\0/;
# copy-through the file data
while ($filesize > 0) {
my $seg = 8192;
$seg = $filesize if $filesize < $seg;
read(STDIN, my $data, $seg);
print $data;
$filesize -= $seg;
}
# If file data is padded, skip it
read(STDIN, my $padding, $filepad) if ($filepad);
}
# pass through any padding at the end (blocksize-dependent)
for (;;) {
my $numread = read(STDIN, my $data, 8192);
last unless $numread;
print $data;
}
exit(0);
sub makedev {
(((($_[0] & 0xff)) << 24) | ($_[1] & 0xffffff));
}
__DATA__
.
# Append to the script the %files data
cat "$@" </dev/null >> $script
/usr/bin/perl $script || pp_error "pp_macos_rewrite_cpio error";
}
#@ pp_rpm_files_bom() < %files: convert file list into input for mkbom
pp_macos_files_bom () {
typeset _l t m o g f p st owner
while read t m o g f p st; do
# make sure that $m is padded up to 4 digits long
case "$m" in
?) m="000$m";;
??) m="00$m";;
???) m="0$m";;
?????*) pp_error "pp_macos_writebom: mode '$m' too long";;
esac
# convert owner,group into owner/group in octal
case $o in -) o=0;; esac
case $g in -) g=0;; esac
owner=`pp_d2o $o`/`pp_d2o $g`
case $t in
f)
test x"$m" = x"000-" && m=0644
echo ".$p 10$m $owner `
/usr/bin/cksum < "${pp_destdir}$p" |
awk '{print $2 " " $1}'`"
;;
d)
test x"$m" = x"000-" && m=0755
echo ".${p%/} 4$m $owner"
;;
s)
test x"$m" = x"000-" && m=0755
rl=`/usr/bin/readlink "${pp_destdir}$p"`
#test x"$rl" = x"$st" ||
# pp_error "symlink mismatch $rl != $st"
echo ".$p 12$m $owner `
/usr/bin/readlink -n "${pp_destdir}$p" |
/usr/bin/cksum |
awk '{print $2 " " $1}'` $st"
;;
esac
done
}
#@ pp_macos_bom_fix_parents ($bomsrc) : inserts missing parents into bom src
pp_macos_bom_fix_parents () {
perl -pe '
sub dirname { my $d=shift; $d=~s,/[^/]*$,,; $d; }
sub chk { my $d=shift;
&chk(&dirname($d)) if $d =~ m,/,;
unless ($seen{$d}++) {
# Make sure we do not override system directories
if ($d =~ m:^\./(etc|var)$:) {
my $tgt = "private/$1";
my ($sum, $len) = split(/\s+/, `/usr/bin/printf "$tgt" | /usr/bin/cksum /dev/stdin`);
print "$d\t120755\t0/0\t$len\t$sum\t$tgt\n";
} elsif ($d eq "." || $d eq "./Library") {
print "$d\t41775\t0/80\n";
} elsif ($d eq "./Applications" || $d eq "./Developer") {
print "$d\t40775\t0/80\n";
} else {
print "$d\t40755\t0/0\n";
}
}
}
m/^(\S+)\s+(\d+)/;
if (oct($2) & 040000) {
$seen{$1}++; # directory
}
&chk(&dirname($1));'
}
#pp_macos_files_size() < %files: compute the occupation size in kB
# Note that each installed file (and directory) has its size rounded up to 4k
pp_macos_files_size () {
typeset _l t m o g f p st owner
while read t m o g f p st; do
case $t in
f) wc -c < "${pp_destdir}$p";;
s) echo 4095;;
d) ;; # always seems to be zero
esac
done | awk '{n+=1+int($1/4096)} END {print n*4}'
}
#@ pp_o2d($oct): prints the decimal form of octal number $oct to stdout
pp_o2d () {
awk 'BEGIN { x=0; '`echo "$1" |
sed -e 's/./x=x*8+&;/g'`'print x;}' </dev/null
}
#@ pp_d2o($dec): prints the octal form of decimal expression $dec to stdout
pp_d2o () {
case "$1" in
[0-7]) echo $1;;
*) awk 'BEGIN { printf("%o\n", 0+('"$1"'));}' < /dev/null;;
esac
}
#@ pp_macos_mkbom(bomls output.bom): build a bom file from a bomls
pp_macos_mkbom () {
#/usr/bin/mkbom -i $1 $2
typeset path mode ugid size cksum linkpath
typeset bomstage
# Use mkbom if it understands -i (avoids a copy)
if /usr/bin/mkbom -i /dev/null "$2" 2>/dev/null; then
rm -f "$2"
/usr/bin/mkbom -i "$1" "$2"
return
fi
# On 10.4 we have this nonsense.
pp_warn "mkbom workaround: copying source files to staging area"
bomstage=$pp_wrkdir/bom_stage
$pp_macos_sudo /bin/mkdir "$bomstage"
while IFS=' ' read path mode ugid size cksumi linkpath; do
if test -h "$pp_destdir/$path"; then
$pp_macos_sudo /bin/ln -s "$linkpath" "$bomstage/$path"
else
if test -d "$pp_destdir/$path"; then
$pp_macos_sudo /bin/mkdir -p "$bomstage/$path"
else
$pp_macos_sudo /bin/cp "$pp_destdir/$path" "$bomstage/$path"
fi
$pp_macos_sudo /bin/chmod $mode "$bomstage/$path"
$pp_macos_sudo /usr/sbin/chown `echo $ugid| tr / :` "$bomstage/$path"
fi
done <"$1"
(cd $bomstage && $pp_macos_sudo mkbom . $pp_wrkdir/bom_stage.bom) ||
pp_error "mkbom failed"
$pp_macos_sudo mv $pp_wrkdir/bom_stage.bom "$2"
}
#@ pp_backend_macos(): processes output files to generate a package files
pp_backend_macos () {
: ${pp_macos_bundle_id:=$pp_macos_default_bundle_id_prefix$name}
case "$pp_macos_pkg_type" in
bundle) pp_backend_macos_bundle;;
flat) pp_backend_macos_flat;;
*) pp_error "unsupported package type $pp_macos_pkg_type";;
esac
}
#@ pp_backend_macos_bundle(): processes output files to generate a package bundle
pp_backend_macos_bundle () {
typeset pkgdir Contents Resources lprojdir svc
typeset Info_plist Description_plist
typeset bundle_vendor bundle_version size cmp filelists
mac_version=`sw_vers -productVersion`
bundle_vendor=${pp_macos_bundle_vendor:-$vendor}
if test -z "$pp_macos_bundle_version"; then
bundle_version=`echo "$version.0.0.0" | sed -n -e 's/[^0-9.]//g' \
-e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
else
bundle_version="$pp_macos_bundle_version"
fi
source_version=`echo $version | sed 's/.*\.//'`
# build the package layout
pkgdir=$pp_wrkdir/$name.pkg
Contents=$pkgdir/Contents
Resources=$Contents/Resources
lprojdir=$Resources/en.lproj
mkdir $pkgdir $Contents $Resources $lprojdir ||
pp_error "Can't make package temporary directories"
echo "major: 1" > $Resources/package_version
echo "minor: 0" >> $Resources/package_version
echo "pmkrpkg1" > $Contents/PkgInfo
case $mac_version in
"10.6"*)
xattr -w "com.apple.TextEncoding" "macintosh;0" "$Resources/package_version"
xattr -w "com.apple.TextEncoding" "macintosh;0" "$Contents/PkgInfo"
;;
esac
# Copy welcome file/dir for display at package install time.
if test -n "$pp_macos_pkg_welcome"; then
typeset sfx
sfx=`echo "$pp_macos_pkg_welcome"|sed 's/^.*\.\([^\.]*\)$/\1/'`
case "$sfx" in
rtf|html|rtfd|txt) ;;
*) sfx=txt;;
esac
cp -R ${pp_macos_pkg_welcome} $Resources/Welcome.$sfx
fi
# Copy readme file/dir for display at package install time.
if test -n "$pp_macos_pkg_readme"; then
typeset sfx
sfx=`echo "$pp_macos_pkg_readme"|sed 's/^.*\.\([^\.]*\)$/\1/'`
case "$sfx" in
rtf|html|rtfd|txt) ;;
*) sfx=txt;;
esac
cp -R ${pp_macos_pkg_readme} $Resources/ReadMe.$sfx
fi
# Copy license file/dir for display at package install time.
if test -n "$pp_macos_pkg_license"; then
typeset sfx
sfx=`echo "$pp_macos_pkg_license"|sed 's/^.*\.\([^\.]*\)$/\1/'`
case "$sfx" in
rtf|html|rtfd|txt) ;;
*) sfx=txt;;
esac
cp -R ${pp_macos_pkg_license} $Resources/License.$sfx
fi
# Add services (may modify %files)
for svc in $pp_services .; do
test . = "$svc" && continue
pp_macos_add_service $svc
done
# Find file lists (%files.* includes ignore files)
for cmp in $pp_components; do
test -f $pp_wrkdir/%files.$cmp && filelists="$filelists${filelists:+ }$pp_wrkdir/%files.$cmp"
done
# compute the installed size
size=`cat $filelists | pp_macos_files_size`
#-- Create Info.plist
Info_plist=$Contents/Info.plist
pp_macos_plist \
start-plist \{ \
key CFBundleGetInfoString string \
"${pp_macos_bundle_info_string:-$version $bundle_vendor}" \
key CFBundleIdentifier string \
"${pp_macos_bundle_id}" \
key CFBundleName string "$name" \
key CFBundleShortVersionString string "$bundle_version.$source_version" \
key IFMajorVersion integer 1 \
key IFMinorVersion integer 0 \
key IFPkgFlagAllowBackRev false \
key IFPkgFlagAuthorizationAction string "RootAuthorization" \
key IFPkgFlagDefaultLocation string "/" \
key IFPkgFlagFollowLinks true \
key IFPkgFlagInstallFat true \
key IFPkgFlagInstalledSize integer $size \
key IFPkgFlagIsRequired false \
key IFPkgFlagOverwritePermissions true \
key IFPkgFlagRelocatable false \
key IFPkgFlagRestartAction string "NoRestart" \
key IFPkgFlagRootVolumeOnly true \
key IFPkgFlagUpdateInstalledLanguages false \
key IFPkgFlagUseUserMask false \
key IFPkgFormatVersion real 0.10000000149011612 \
key SourceVersion string $source_version \
\} end-plist> $Info_plist
# write en.lproj/Description.plist
Description_plist=$lprojdir/Description.plist
pp_macos_plist \
start-plist \{ \
key IFPkgDescriptionDeleteWarning string "" \
key IFPkgDescriptionDescription string "$pp_macos_bundle_info_string" \
key IFPkgDescriptionTitle string "$name" \
key IFPkgDescriptionVersion string "$bundle_version.$source_version" \
\} end-plist > $Description_plist
# write Resources/files
awk '{print $6}' $filelists > $Resources/files
# write package size file
printf \
"NumFiles 0
InstalledSize $size
CompressedSize 0
" > $Resources/$name.sizes
# write Resources/preinstall
for cmp in $pp_components; do
if test -s $pp_wrkdir/%pre.$cmp; then
if test ! -s $Resources/preinstall; then
echo "#!/bin/sh" > $Resources/preinstall
chmod +x $Resources/preinstall
fi
cat $pp_wrkdir/%pre.$cmp >> $Resources/preinstall
echo : >> $Resources/preinstall
fi
done
# write Resources/postinstall
for cmp in $pp_components; do
if test -s $pp_wrkdir/%post.$cmp; then
if test ! -s $Resources/postinstall; then
echo "#!/bin/sh" > $Resources/postinstall
chmod +x $Resources/postinstall
fi
cat $pp_wrkdir/%post.$cmp >> $Resources/postinstall
echo : >> $Resources/postinstall
fi
done
# write Resources/postupgrade
for cmp in $pp_components; do
if test -s $pp_wrkdir/%postup.$cmp; then
if test ! -s $Resources/postupgrade; then
echo "#!/bin/sh" > $Resources/postupgrade
chmod +x $Resources/postupgrade
fi
cat $pp_wrkdir/%postup.$cmp >> $Resources/postupgrade
echo : >> $Resources/postupgrade
fi
done
# write Resources/preremove
for cmp in $pp_components; do
if test -s $pp_wrkdir/%preun.$cmp; then
if test ! -s $Resources/preremove; then
echo "#!/bin/sh" > $Resources/preremove
chmod +x $Resources/preremove
fi
cat $pp_wrkdir/%preun.$cmp >> $Resources/preremove
echo : >> $Resources/preremove
fi
done
# write Resources/postremove
for cmp in $pp_components; do
if test -s $pp_wrkdir/%postun.$cmp; then
if test ! -s $Resources/postremove; then
echo "#!/bin/sh" > $Resources/postremove
chmod +x $Resources/postremove
fi
cat $pp_wrkdir/%postun.$cmp >> $Resources/postremove
echo : >> $Resources/postremove
fi
done
# write uninstall info
echo "version=$version" > $Resources/uninstall
if [ -n "$pp_macos_requires" ];then
echo "requires=$pp_macos_requires" >> $Resources/uninstall
fi
. $pp_wrkdir/%fixup
# Create the bill-of-materials (Archive.bom)
cat $filelists | pp_macos_files_bom | sort |
pp_macos_bom_fix_parents > $pp_wrkdir/tmp.bomls
pp_macos_mkbom $pp_wrkdir/tmp.bomls $Contents/Archive.bom
# Create the cpio archive (Archive.pax.gz)
(
cd $pp_destdir &&
awk '{ print "." $6 }' $filelists | sed 's:/$::' | sort | /usr/bin/cpio -o | pp_macos_rewrite_cpio $filelists | gzip -9f -c > $Contents/Archive.pax.gz
)
# Copy installer plugins if any
if test -n "$pp_macos_installer_plugin"; then
if test ! -f "$pp_macos_installer_plugin/InstallerSections.plist"; then
pp_error "Missing InstallerSections.plist file in $pp_macos_installer_plugin"
fi
mkdir -p $pkgdir/Plugins
cp -R "$pp_macos_installer_plugin"/* $pkgdir/Plugins
fi
test -d $pp_wrkdir/bom_stage && $pp_macos_sudo rm -rf $pp_wrkdir/bom_stage
rm -f ${name}-${version}.dmg
hdiutil create -fs HFS+ -srcfolder $pkgdir -volname $name ${name}-${version}.dmg
}
#@ pp_backend_macos_flat(): processes output files to generate a flat package
pp_backend_macos_flat () {
typeset pkgdir bundledir Resources lprojdir svc
typeset Info_plist Description_plist
typeset bundle_vendor bundle_version size numfiles cmp filelists
mac_version=`sw_vers -productVersion`
bundle_vendor=${pp_macos_bundle_vendor:-$vendor}
if test -z "$pp_macos_bundle_version"; then
bundle_version=`echo "$version.0.0.0" | sed -n -e 's/[^0-9.]//g' \
-e 's/^\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p'`
else
bundle_version="$pp_macos_bundle_version"
fi
source_version=`echo $version | sed 's/.*\.//'`
# build the flat package layout
pkgdir=$pp_wrkdir/pkg
pkgfile=$name-$version.pkg
bundledir=$pp_wrkdir/pkg/$pkgfile
Resources=$pkgdir/Resources
lprojdir=$Resources/en.lproj
mkdir $pkgdir $bundledir $Resources $lprojdir ||
pp_error "Can't make package temporary directories"
# Add services (may modify %files)
for svc in $pp_services .; do
test . = "$svc" && continue
pp_macos_add_service $svc
done
# Find file lists (%files.* includes ignore files)
for cmp in $pp_components; do
test -f $pp_wrkdir/%files.$cmp && filelists="$filelists${filelists:+ }$pp_wrkdir/%files.$cmp"
done
# compute the installed size and number of files/dirs
size=`cat $filelists | pp_macos_files_size`
numfiles=`cat $filelists | wc -l`
numfiles="${numfiles##* }"
# Write Distribution file
cat <<-. >$pkgdir/Distribution
<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion="1">
<title>$name $version</title>
<options customize="never" allow-external-scripts="no"/>
<domains enable_localSystem="true"/>
.
if test -n "$pp_macos_pkg_welcome"; then
cp -R "${pp_macos_pkg_welcome}" $Resources
echo " <welcome file=\"${pp_macos_pkg_welcome##*/}\"/>" >>$pkgdir/Distribution
fi
if test -n "$pp_macos_pkg_readme"; then
cp -R "${pp_macos_pkg_readme}" $Resources
echo " <readme file=\"${pp_macos_pkg_readme##*/}\"/>" >>$pkgdir/Distribution
fi
if test -n "$pp_macos_pkg_license"; then
cp -R "${pp_macos_pkg_license}" $Resources
echo " <license file=\"${pp_macos_pkg_license##*/}\"/>" >>$pkgdir/Distribution
fi
if test -n "$pp_macos_pkg_background"; then
cp -R "${pp_macos_pkg_background}" $Resources
echo " <background file=\"${pp_macos_pkg_background##*/}\" scaling=\"proportional\" alignment=\"left\"/>" >>$pkgdir/Distribution
fi
if test -n "$pp_macos_pkg_background_dark"; then
cp -R "${pp_macos_pkg_background_dark}" $Resources
echo " <background-darkAqua file=\"${pp_macos_pkg_background_dark##*/}\" scaling=\"proportional\" alignment=\"left\"/>" >>$pkgdir/Distribution
fi
cat <<-. >>$pkgdir/Distribution
<choices-outline>
<line choice="choice0"/>
</choices-outline>
<choice id="choice0" title="$name $version">
<pkg-ref id="${pp_macos_bundle_id}"/>
</choice>
<pkg-ref id="${pp_macos_bundle_id}" installKBytes="$size" version="$version" auth="Root">#$pkgfile</pkg-ref>
</installer-gui-script>
.
# write scripts archive
# XXX - missing preupgrade, preflight, postflight
mkdir $pp_wrkdir/scripts
for cmp in $pp_components; do
if test -s $pp_wrkdir/%pre.$cmp; then
if test ! -s $pp_wrkdir/scripts/preinstall; then
echo "#!/bin/sh" > $pp_wrkdir/scripts/preinstall
chmod +x $pp_wrkdir/scripts/preinstall
fi
cat $pp_wrkdir/%pre.$cmp >> $pp_wrkdir/scripts/preinstall
echo : >> $pp_wrkdir/scripts/preinstall
fi
if test -s $pp_wrkdir/%post.$cmp; then
if test ! -s $pp_wrkdir/scripts/postinstall; then
echo "#!/bin/sh" > $pp_wrkdir/scripts/postinstall
chmod +x $pp_wrkdir/scripts/postinstall
fi
cat $pp_wrkdir/%post.$cmp >> $pp_wrkdir/scripts/postinstall
echo : >> $pp_wrkdir/scripts/postinstall
fi
if test -s $pp_wrkdir/%postup.$cmp; then
if test ! -s $pp_wrkdir/scripts/postupgrade; then
echo "#!/bin/sh" > $pp_wrkdir/scripts/postupgrade
chmod +x $pp_wrkdir/scripts/postupgrade
fi
cat $pp_wrkdir/%postup.$cmp >> $pp_wrkdir/scripts/postupgrade
echo : >> $pp_wrkdir/scripts/postupgrade
fi
# XXX - not supported
if test -s $pp_wrkdir/%preun.$cmp; then
if test ! -s $pp_wrkdir/scripts/preremove; then
echo "#!/bin/sh" > $pp_wrkdir/scripts/preremove
chmod +x $pp_wrkdir/scripts/preremove
fi
cat $pp_wrkdir/%preun.$cmp >> $pp_wrkdir/scripts/preremove
echo : >> $pp_wrkdir/scripts/preremove
fi
# XXX - not supported
if test -s $pp_wrkdir/%postun.$cmp; then
if test ! -s $pp_wrkdir/scripts/postremove; then
echo "#!/bin/sh" > $pp_wrkdir/scripts/postremove
chmod +x $pp_wrkdir/scripts/postremove
fi
cat $pp_wrkdir/%postun.$cmp >> $pp_wrkdir/scripts/postremove
echo : >> $pp_wrkdir/scripts/postremove
fi
done
if test "`echo $pp_wrkdir/scripts/*`" != "$pp_wrkdir/scripts/*"; then
# write scripts archive, scripts are mode 0755 uid/gid 0/0
# resetting the owner and mode is not strictly required
(
cd $pp_wrkdir/scripts || pp_error "Can't cd to $pp_wrkdir/scripts"
rm -f $pp_wrkdir/tmp.files.scripts
for s in *; do
echo "f 0755 0 0 - ./$s" >>$pp_wrkdir/tmp.files.scripts
done
find . -type f | /usr/bin/cpio -o | pp_macos_rewrite_cpio $pp_wrkdir/tmp.files.scripts | gzip -9f -c > $bundledir/Scripts
)
fi
# Write PackageInfo file
cat <<-. >$bundledir/PackageInfo
<?xml version="1.0" encoding="UTF-8"?>
<pkg-info format-version="2" identifier="${pp_macos_bundle_id}" version="$version" install-location="/" relocatable="false" overwrite-permissions="true" followSymLinks="true" auth="root">
<payload installKBytes="$size" numberOfFiles="$numfiles"/>
.
if test -s $bundledir/Scripts; then
echo " <scripts>" >>$bundledir/PackageInfo
for s in preflight postflight preinstall postinstall preupgrade postupgrade; do
if test -s "$pp_wrkdir/scripts/$s"; then
echo " <$s file=\"$s\"/>" >>$bundledir/PackageInfo
fi
done
echo " </scripts>" >>$bundledir/PackageInfo
fi
cat <<-. >>$bundledir/PackageInfo
</pkg-info>
.
. $pp_wrkdir/%fixup
# Create the bill-of-materials (Bom)
cat $filelists | pp_macos_files_bom | sort |
pp_macos_bom_fix_parents > $pp_wrkdir/tmp.bomls
pp_macos_mkbom $pp_wrkdir/tmp.bomls $bundledir/Bom
# Create the cpio payload
(
cd $pp_destdir || pp_error "Can't cd to $pp_destdir"
awk '{ print "." $6 }' $filelists | sed 's:/$::' | sort | /usr/bin/cpio -o | pp_macos_rewrite_cpio $filelists | gzip -9f -c > $bundledir/Payload
)
awk '{print $6}' $filelists > $name.files
# Copy installer plugins if any
if test -n "$pp_macos_installer_plugin"; then
if test ! -f "$pp_macos_installer_plugin/InstallerSections.plist"; then
pp_error "Missing InstallerSections.plist file in $pp_macos_installer_plugin"
fi
mkdir -p $pkgdir/Plugins
cp -R "$pp_macos_installer_plugin"/* $pkgdir/Plugins
fi
test -d $pp_wrkdir/bom_stage && $pp_macos_sudo rm -rf $pp_wrkdir/bom_stage
# Create the flat package with xar (like pkgutil --flatten does)
# Note that --distribution is only supported by macOS 10.6 and above
xar_flags="--compression=bzip2 --no-compress Scripts --no-compress Payload"
case $mac_version in
"10.5"*) ;;
*) xar_flags="$xar_flags --distribution";;
esac
(cd $pkgdir && /usr/bin/xar $xar_flags -cf "../$pkgfile" *)
echo "version=$version" > $name.uninstall
}
#@ pp_backend_macos_cleanup(): removes any files created outside $pp_wrkdir
pp_backend_macos_cleanup () {
:
}
#@ pp_backend_macos_names(): prints the paths to package files
# each path should start with $name-$version
# the package must be relative to the $pp_wrkdir directory
pp_backend_macos_names () {
case "$pp_macos_pkg_type" in
bundle) echo ${name}.pkg;;
flat) echo ${name}-${version}.pkg;;
*) pp_error "unsupported package type $pp_macos_pkg_type";;
esac
}
#@ pp_backend_macos_install_script(component): generate helper install script
pp_backend_macos_install_script () {
echo '#!/bin/sh'
typeset pkgname platform
pkgname="`pp_backend_macos_names`"
platform="`pp_backend_macos_probe`"
pp_install_script_common
cat <<.
test \$# -eq 0 && usage
op="\$1"; shift
case "\$op" in
list-components)
test \$# -eq 0 || usage \$op
echo "$pp_components"
;;
list-services)
test \$# -eq 0 || usage \$op
echo "$pp_services"
;;
list-files)
test \$# -ge 1 || usage \$op
echo \${PP_PKGDESTDIR:-.}/"$pkgname"
;;
install)
test \$# -ge 1 || usage \$op
vol=/Volumes/pp\$\$
pkg=\$vol/${name}-${version}.pkg
hdiutil attach -readonly -mountpoint \$vol \
\${PP_PKGDESTDIR:-.}/"$pkgname"
trap "hdiutil detach \$vol" 0
installer -pkginfo -pkg \$pkg
installer -verbose -pkg \$pkg -target /
;;
uninstall)
test \$# -ge 1 || usage \$op
# XXX
echo "Uninstall not implemented" >&2
exit 1;;
start|stop)
test \$# -ge 1 || usage \$op
ec=0
for svc
do
# XXX
echo "\${op} not implemented" >&2
ec=1
done
exit \$ec
;;
print-platform)
echo "$platform"
;;
*)
usage;;
esac
.
}
#@ pp_backend_macos_init_svc_vars(): initialise service vars
pp_backend_macos_init_svc_vars () {
pp_macos_start_services_after_install=true
pp_macos_service_name=
pp_macos_default_service_id_prefix="com.quest.rc."
pp_macos_service_id=
pp_macos_service_user=
pp_macos_service_group=
pp_macos_service_initgroups=
pp_macos_service_umask=
pp_macos_service_cwd=
pp_macos_service_nice=
pp_macos_svc_plist_file=
}
#@ pp_macos_launchd_plist(svc): create a launched plist file for /Library/LaunchDaemons
pp_macos_launchd_plist () {