-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrepo2svr4.sh
executable file
·1628 lines (1564 loc) · 36 KB
/
repo2svr4.sh
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
#!/bin/ksh
#
# SPDX-License-Identifier: CDDL-1.0
#
# {{{ CDDL HEADER
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# }}}
#
# Copyright 2025 Peter Tribble
#
#
# convert an ips package to svr4, from an on-disk repo
#
PKG_VERSION="0.36.1"
THOME=${THOME:-/packages/localsrc/Tribblix}
GATEDIR=/export/home/ptribble/Illumos/illumos-gate
DSTDIR=/var/tmp/illumos-pkgs
SIGNCERT=""
MYREPO="redist"
QUICKMODE=""
ARCH32=$(uname -p)
#
# find_elf can't find the right elfedit
#
export PATH=/usr/bin:/usr/sbin:/sbin:/usr/gnu/bin
#
# packages should have consistent times
#
TZ=UTC
export TZ
#
# locations and variables should be passed as arguments
#
while getopts "QV:T:G:D:R:S:" opt; do
case $opt in
Q)
QUICKMODE="Y"
;;
V)
PKG_VERSION="$OPTARG"
;;
T)
THOME="$OPTARG"
;;
G)
GATEDIR="$OPTARG"
;;
D)
DSTDIR="$OPTARG"
;;
R)
MYREPO="$OPTARG"
;;
S)
SIGNCERT="$OPTARG"
;;
esac
done
shift $((OPTIND-1))
#
# verify signing - the cert and key must exist
# if they don't, exit early
#
FINDELF=${GATEDIR}/usr/src/tools/scripts/find_elf
if [ -n "$SIGNCERT" ]; then
if [ -r "${SIGNCERT}.key" -a -r "${SIGNCERT}.crt" ]; then
:
else
echo "Error: invalid cert specified"
exit 1
fi
if [ ! -x "${FINDELF}" ]; then
FINDELF="${GATEDIR}/usr/src/tools/find_elf/find_elf"
fi
if [ ! -x "${FINDELF}" ]; then
FINDELF="/opt/onbld/bin/find_elf"
fi
if [ ! -x "${FINDELF}" ]; then
FINDELF="/opt/onbld/bin/${ARCH32}/find_elf"
fi
if [ ! -x "${FINDELF}" ]; then
echo "Cannot sign, find_elf missing"
exit 1
fi
if [ ! -x /usr/bin/elfsign ]; then
echo "Cannot sign, elfsign missing"
echo " (is TRIBdev-linker installed?)"
exit 1
fi
fi
#
# high level strategy:
#
# 1. create a new temporary directory
# 2. parse manifests to build an svr4 proto area
# 3. create the svr4 package
#
# conversion strategy:
#
# 1. construct arch variant list
# 2. create a new directory for each architecture (or common if no arch)
# 3. Copy all relevant files into target directory hierarchy, using
# manifest to map pathnames and build the prototype file as we go
# 4. create a pkginfo file from manifest or manifest.legacy (if it exists)
# 5. Create install/depend from depend actions in the manifest,
# ignoring incorporations
# 7. run pkgmk
#
#
# weaknesses of the current implementation
# 1. no attempt at architecture variants
# 2. fixed paths
# 3. need to fully handle set actions
# 4. need to fully handle driver actions
# 5. handle reboot-needed
# 6. Need to handle global/ngz
#
#
# Global variables
#
PKGDIR=/usr/bin
PKGMK="${PKGDIR}/pkgmk"
PKGTRANS="${PKGDIR}/pkgtrans"
PNAME=${THOME}/tribblix-build/pkg_name.sh
TRANSDIR=${THOME}/tribblix-transforms
#
# used for noisaexec
#
case $ARCH32 in
sparc)
ARCH64="sparcv9"
;;
i386)
ARCH64="amd64"
;;
esac
#
# global flags
#
# contains a legacy action
HAS_LEGACY=false
# contains any content
HAS_CONTENT=false
# is marked as renamed or obsolete
IS_GARBAGE=false
usage() {
echo "Usage: $0 input_pkg output_pkg"
exit 1
}
bail_out() {
rm -fr "$BDIR" "$DSTDIR/tmp/${OUTPKG}"
exit 0
}
#
# some drivers (ata is the only example I know of) claim more than 1 class
# I can't find a way for add_drv to cope with this, so resort to
# fiddling /etc/driver_classes by hand
#
# I assume that init_driver has been called already
#
# first argument is the driver, 2nd the class
#
add_driver_class() {
NDRIVER=$1
NCLASS=$2
cat >>"${BDIR}/install/postinstall" <<EOF
echo "$NDRIVER\t$NCLASS" >> \${BASEDIR}/etc/driver_classes
EOF
cat >>"${BDIR}/install/postremove" <<EOF
cat \${BASEDIR}/etc/driver_classes | /bin/sed '/^${NDRIVER}.*${NCLASS}/d' > /tmp/adc.\$\$
cp /tmp/adc.\$\$ \${BASEDIR}/etc/driver_classes
rm /tmp/adc.\$\$
EOF
}
#
# initialize driver handling by creating the postinstall and postremove
# scripts
#
init_driver() {
mkdir -p "${BDIR}/install"
if [ ! -f "${BDIR}/install/postinstall" ]; then
cat > "${BDIR}/install/postinstall" <<EOF
#!/sbin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# Automatically generated driver install script
#
CMD=/usr/sbin/add_drv
if [ "\${BASEDIR}" = "/" ]; then
BFLAGS=""
else
BFLAGS="-b \${BASEDIR}"
fi
EOF
cat > "${BDIR}/install/postremove" <<EOF
#!/sbin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# Automatically generated driver remove script
#
CMD=/usr/sbin/rem_drv
if [ "\${BASEDIR}" = "/" ]; then
BFLAGS=""
else
BFLAGS="-b \${BASEDIR}"
fi
EOF
echo "i postinstall=./install/postinstall" >> "${BDIR}/prototype"
echo "i postremove=./install/postremove" >> "${BDIR}/prototype"
fi
}
#
# class action scripts
#
init_preserve() {
mkdir -p "${BDIR}/install"
if [ ! -f "${BDIR}/install/i.preserve" ]; then
cat > "${BDIR}/install/i.preserve" <<EOF
#!/bin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# simplistic class-action script for preserve
# copies the new file iff it doesn't already exist
#
while read src dest
do
if [ ! -f \$dest ] ; then
cp \$src \$dest
fi
done
exit 0
EOF
chmod 555 "${BDIR}/install/i.preserve"
echo "i i.preserve=./install/i.preserve" >> "${BDIR}/prototype"
fi
if [ ! -f "${BDIR}/install/r.preserve" ]; then
cat > "${BDIR}/install/r.preserve" <<EOF
#!/bin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# class-action script for preserve
# retains the old file if it's been modified
#
while read dest
do
# need to strip off the alternate root
ndest=\${dest/\${PKG_INSTALL_ROOT}/}
if [ -f "\${PKG_INSTALL_ROOT}/var/sadm/pkg/\${PKGINST}/save/pspool/\${PKGINST}/reloc/\${ndest}" ]; then
if /usr/bin/cmp -s "\${PKG_INSTALL_ROOT}/var/sadm/pkg/\${PKGINST}/save/pspool/\${PKGINST}/reloc/\${ndest}" "\${dest}"
then
/usr/bin/rm -f \$dest
else
echo Retaining modified \$dest
fi
fi
done
exit 0
EOF
chmod 555 "${BDIR}/install/r.preserve"
echo "i r.preserve=./install/r.preserve" >> "${BDIR}/prototype"
fi
}
#
# initialise dependency handling
#
init_depend() {
mkdir -p "${BDIR}/install"
if [ ! -f "${BDIR}/install/depend" ]; then
cat > "${BDIR}/install/depend" <<EOF
# The following dependencies are automatically generated
# from the IPS manifest for this package, with automatic
# generation of SVR4 package names.
#
# No version information is preserved
#
EOF
echo "i depend=./install/depend" >> "${BDIR}/prototype"
fi
}
#
# if there are services that should be restarted, add them to the postinstall
# script
#
handle_restarts() {
if [ -f "${BDIR}/restart_fmri_list" ]; then
mkdir -p "${BDIR}/install"
if [ ! -f "${BDIR}/install/postinstall" ]; then
cat > "${BDIR}/install/postinstall" <<EOF
#!/sbin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# Automatically generated service restart script
#
EOF
cat > "${BDIR}/install/postremove" <<EOF
#!/sbin/sh
#
# SPDX-License-Identifier: CDDL-1.0
#
# Automatically generated service restart script
#
EOF
echo "i postinstall=./install/postinstall" >> "${BDIR}/prototype"
echo "i postremove=./install/postremove" >> "${BDIR}/prototype"
fi
#
# this check is so we only actually restart if the install is to the
# current system. If we're installing to an alternate image, then the
# restarts will happen automatically when it boots
#
# FIXME should the restart be -s
#
cat >> "${BDIR}/install/postinstall" <<EOF
if [ "\${BASEDIR}" = "/" ]; then
EOF
cat >> "${BDIR}/install/postremove" <<EOF
if [ "\${BASEDIR}" = "/" ]; then
EOF
sort -u "${BDIR}/restart_fmri_list" | /usr/bin/awk '{print "/usr/sbin/svcadm restart "$1}' >> "${BDIR}/install/postinstall"
sort -u "${BDIR}/restart_fmri_list" | /usr/bin/awk '{print "/usr/sbin/svcadm restart "$1}' >> "${BDIR}/install/postremove"
echo "fi" >> "${BDIR}/install/postinstall"
echo "fi" >> "${BDIR}/install/postremove"
/usr/bin/rm "${BDIR}/restart_fmri_list"
fi
}
#
# parse a driver line in the manifest
# should have name, maybe alias and perms
# FIXME policy privilege
# FIXME aliases perms etc should be emitted with single quotes
#
handle_driver() {
HAS_CONTENT=true
init_driver
CMD_FRAG='${CMD} ${BFLAGS}'
UCMD_FRAG='/usr/sbin/update_drv ${BFLAGS}'
DNAME=""
PERMS=""
POLICY=""
CLONEPERMS=""
ALIASES=""
CLASS=""
EXTRA_CLASSES=""
for frag in "$@"
do
key=${frag%%=*}
nval=${frag#*=}
value=${nval%%=*}
case $key in
name)
DNAME="$value"
;;
perms)
if [ "x${PERMS}" = "x" ]; then
PERMS="-m '$value'"
else
PERMS="${PERMS},""'$value'"
fi
;;
policy)
#
# there should only be one policy, and it's the whole string
#
POLICY="-p '$nval'"
;;
alias)
if [ "x${ALIASES}" = "x" ]; then
ALIASES="-i '"'"'$value'"'
else
ALIASES="${ALIASES} "'"'$value'"'
fi
;;
class)
if [ "x${CLASS}" = "x" ]; then
CLASS="-c $value"
else
EXTRA_CLASSES="${EXTRA_CLASSES} $value"
fi
;;
*zone*)
:
;;
clone_perms)
CLONEPERMS="'$value'"
;;
*)
echo "unhandled driver action $frag"
;;
esac
done
#
# add any extra driver classes
#
for NCLASS in $EXTRA_CLASSES
do
add_driver_class $DNAME $NCLASS
done
#
# ddi_pseudo confuses the parser, override where it breaks
#
if [ "x${INPKG}" = "xdriver%2Fx11%2Fxsvc" ]; then
DNAME="xsvc"
fi
if [ "x${INPKG}" = "xdriver%2Fstorage%2Fcpqary3" ]; then
DNAME="cpqary3"
fi
if [ "x${INPKG}" = "xdriver%2Fcrypto%2Ftpm" ]; then
DNAME="tpm"
PERMS="-m '* 0600 root sys'"
fi
if [ "x${ALIASES}" != "x" ]; then
ALIASES="${ALIASES}'"
fi
if [ "x${DNAME}" != "x" ]; then
echo "${CMD_FRAG} ${PERMS} ${POLICY} ${ALIASES} ${CLASS} $DNAME" >> "${BDIR}/install/postinstall"
echo "${CMD_FRAG} $DNAME" >> "${BDIR}/install/postremove"
fi
if [ "x${CLONEPERMS}" != "x" ]; then
echo "${UCMD_FRAG} -a -m ${CLONEPERMS} clone" >> "${BDIR}/install/postinstall"
fi
}
#
# parse a directory line in the manifest
# should have group, owner, mode, and path
#
handle_dir() {
HAS_CONTENT=true
for frag in $*
do
key=${frag%%=*}
nval=${frag#*=}
value=${nval%%=*}
case $key in
*zone*)
# FIXME zone handling
:
;;
path)
dirpath=$value
;;
mode)
mode=$value
;;
owner)
owner=$value
;;
group)
group=$value
;;
facet*)
:
;;
*)
echo "unhandled dir attributes $frag"
;;
esac
done
mkdir -p -m "$mode" "${BDIR}/${dirpath}"
echo "d none ${dirpath} ${mode} ${owner} ${group}" >> "${BDIR}/prototype"
}
#
# parse a link line in the manifest
# should have path and target
# skip reboot-needed; handle it with the target file
#
handle_link() {
HAS_CONTENT=true
for frag in $*
do
key=${frag%%=*}
nval=${frag#*=}
value=${nval%%=*}
case $key in
*zone*|reboot-needed)
# FIXME zone handling
:
;;
path)
dirpath=$value
;;
target)
target=$value
;;
facet*)
:
;;
restart_fmri)
:
;;
*)
echo "unhandled link attribute $frag"
;;
esac
done
echo "s none ${dirpath}=${target}" >> "${BDIR}/prototype"
# create the symlink so that rrmdir works
# the directory containing the symlink must exist
tdir=${dirpath%/*}
if [ ! -d "${BDIR}/${tdir}" ]; then
mkdir -p "${BDIR}/${tdir}"
fi
ln -s "${target}" "${BDIR}/${dirpath}"
}
#
# parse a hardlink line in the manifest
# should have path and target
#
handle_hardlink() {
HAS_CONTENT=true
for frag in $*
do
key=${frag%%=*}
nval=${frag#*=}
value=${nval%%=*}
case $key in
*zone*)
# FIXME zone handling
:
;;
path)
dirpath=$value
;;
target)
target=$value
;;
*)
echo "unhandled hardlink attribute $frag"
;;
esac
done
case ${target} in
*~*)
echo "WARNING: skipping link to $target"
;;
*)
echo "l none ${dirpath}=${target}" >> "${BDIR}/prototype"
;;
esac
}
#
# parse a file line in the manifest
# should have group, owner, mode, and path like a directory
# plus some metadata
# ignore the pkg.size and pkg.csize attributes we don't use them anyway
# ignore chash and elfhash, as we don't use them either
#
# cp -p retains the timestamp; this allows repeated invocations of this
# script to generate identical packages, but if the timestamp is set in
# the manifest we explicitly touch the file to that date
#
handle_file() {
HAS_CONTENT=true
FTYPE="f"
FCLASS="none"
TSTAMP=""
echo $* | read fhash line
fh=`echo $fhash| cut -c1-2`
# file in the repo is ${REPODIR}/file/${fh}/${fhash}
for frag in $line
do
key=${frag%%=*}
nval=${frag#*=}
value=${nval%%=*}
case $key in
pkg.size*|pkg.csize*|reboot-needed|*zone*|elfarch|elfbits|chash|elfhash|original_name)
# FIXME reboot, zone handling
# FIXME should check on elfarch
:
;;
path)
filepath=$value
;;
mode)
mode=$value
;;
owner)
owner=$value
;;
group)
group=$value
;;
timestamp)
# timestamp=19700101T000000Z
# touch argument is of the form [[CC]YY]MMDDhhmm[.SS]
TSTAMP=`echo $value | /usr/bin/awk -FT '{printf("%s%.4s",$1,$2)}'`
;;
facet*)
:
;;
pkg.content-hash)
:
;;
restart_fmri)
touch "${BDIR}/restart_fmri_list"
echo $value >>"${BDIR}/restart_fmri_list"
;;
preserve)
FTYPE="e"
FCLASS="preserve"
init_preserve
;;
*)
echo "unhandled file attribute $frag"
;;
esac
done
dpath=`dirname $filepath`
if [ ! -d "${BDIR}/${dpath}" ]; then
mkdir -p "${BDIR}/${dpath}"
fi
if [ -f "${BDIR}/${filepath}" ]; then
echo "DBG: parsing $hash $line"
echo "WARN: path $filepath already exists in $dpath"
fi
/usr/bin/cp -p "${REPODIR}/file/${fh}/${fhash}" "${BDIR}/${filepath}.gz"
/usr/bin/gunzip "${BDIR}/${filepath}.gz"
/usr/bin/chmod "$mode" "${BDIR}/${filepath}"
if [ "xx${TSTAMP}" != "xx" ]; then
/bin/touch -t "${TSTAMP}" "${BDIR}/${filepath}"
fi
case ${filepath} in
*~*)
echo "WARNING: skipping file path $filepath"
;;
*)
echo "${FTYPE} ${FCLASS} ${filepath}=${filepath} ${mode} ${owner} ${group}" >> "${BDIR}/prototype"
;;
esac
}
#
# parse a license line in the manifest
#
# all license files get placed under /var/sadm/license in a directory
# named after the package, in parallel with the /var/sadm/pkg hierarchy
#
handle_license() {
dirmode="0755"
mode="0644"
owner="root"
group="sys"
echo $* | read fhash line
fh=`echo $fhash| cut -c1-2`
# file in the repo is ${REPODIR}/file/${fh}/${fhash}
for frag in $line
do
key=${frag%%=*}
nval=${frag#*=}
value=${nval%%=*}
case $key in
license)
licpath=$value
;;
*)
:
;;
esac
done
if [ -n "$licpath" ]; then
dirpath="var/sadm/license/${PKG}"
if [ ! -d "${BDIR}/${dirpath}" ]; then
mkdir -p "${BDIR}/${dirpath}"
fi
echo "d none ${dirpath} ${dirmode} ${owner} ${group}" >> "${BDIR}/prototype"
case $licpath in
*/*)
licfname=${licpath##*/}
;;
cr_*)
licfname=${licpath/cr_/COPYRIGHT.}
;;
lic_*)
:
licfname=${licpath/lic_/LICENSE.}
;;
license_in_headers)
licfname="SEE_HEADERS.txt"
;;
esac
#
# if the candidate name already exists, try adding a suffix
#
if [ -f "${BDIR}/${dirpath}/${licfname}" ]; then
NLIC=1
while [ -f "${BDIR}/${dirpath}/${licfname}.${NLIC}" ]
do
NLIC=$((NLIC+1))
done
licfname="${licfname}.${NLIC}"
fi
filepath="${dirpath}/${licfname}"
/usr/bin/cp -p "${REPODIR}/file/${fh}/${fhash}" "${BDIR}/${filepath}.gz"
/usr/bin/gunzip "${BDIR}/${filepath}.gz"
/usr/bin/chmod "$mode" "${BDIR}/${filepath}"
echo "f none ${filepath}=${filepath} ${mode} ${owner} ${group}" >> "${BDIR}/prototype"
fi
}
#
# parse a legacy line in the manifest
#
# This doesn't always work, as the legacy action maps to the SVR4 emulation
# layer. So there could be multiple legacy actions, in the case of merged
# packages, or none at all.
#
# none at all is bad, as that causes an incomplete pkginfo file which causes
# package generation to fail
#
handle_legacy() {
HAS_LEGACY=true
for frag in "$*"
do
eval "$frag"
done
NAME=`echo $name| sed -e 's:, (Root)::' -e 's: (Root)::' -e 's:, (Usr)::' -e 's: (Usr)::' -e 's: (root)::'`
VERSION="$PKG_VERSION"
IPS_VERSION="$version"
ARCH="$arch"
CATEGORY="$category"
VENDOR="$vendor"
BASEDIR="/"
PKG="$OUTPKG"
DESC="$desc"
# FIXME why null?
# the problem appears to be if a legacy line includes a facet
if [ "x$IPS_VERSION" = "x" ]; then
IPS_VERSION="1.0"
fi
# CLASSES automatically set by pkgmk
echo "PKG=\"${PKG}\"" >> "${BDIR}/pkginfo"
echo "NAME=\"${NAME}\"" >> "${BDIR}/pkginfo"
echo "ARCH=\"${ARCH}\"" >> "${BDIR}/pkginfo"
echo "VERSION=\"${VERSION}\"" >> "${BDIR}/pkginfo"
echo "IPS_VERSION=\"${IPS_VERSION}\"" >> "${BDIR}/pkginfo"
echo "CATEGORY=\"${CATEGORY}\"" >> "${BDIR}/pkginfo"
echo "VENDOR=\"${VENDOR}\"" >> "${BDIR}/pkginfo"
echo "BASEDIR=\"${BASEDIR}\"" >> "${BDIR}/pkginfo"
echo "PSTAMP=\"tribblix\"" >> "${BDIR}/pkginfo"
}
emulate_legacy() {
HAS_LEGACY=true
NAME="$OUTPKG"
VERSION="$PKG_VERSION"
ARCH="$ARCH32"
CATEGORY="application"
VENDOR="Tribblix"
BASEDIR="/"
PKG="$OUTPKG"
# FIXME should be pkg.summary
DESC="$OUTPKG"
# CLASSES automatically set by pkgmk
echo "PKG=\"${PKG}\"" >> "${BDIR}/pkginfo"
echo "NAME=\"${NAME}\"" >> "${BDIR}/pkginfo"
echo "ARCH=\"${ARCH}\"" >> "${BDIR}/pkginfo"
echo "VERSION=\"${VERSION}\"" >> "${BDIR}/pkginfo"
echo "CATEGORY=\"${CATEGORY}\"" >> "${BDIR}/pkginfo"
echo "VENDOR=\"${VENDOR}\"" >> "${BDIR}/pkginfo"
echo "BASEDIR=\"${BASEDIR}\"" >> "${BDIR}/pkginfo"
echo "PSTAMP=\"tribblix\"" >> "${BDIR}/pkginfo"
}
#
# parse set directives
#
handle_set() {
for frag in "$*"
do
eval "$frag"
done
case $name in
'pkg.renamed')
IS_GARBAGE=true
;;
'pkg.obsolete')
IS_GARBAGE=true
;;
'pkg.description')
echo "IPS_DESCRIPTION=$value" >> "${BDIR}/pkginfo"
;;
'pkg.summary')
echo "IPS_SUMMARY=$value" >> "${BDIR}/pkginfo"
;;
'pkg.fmri')
echo "IPS_FMRI=$value" >> "${BDIR}/pkginfo"
;;
'info.classification')
echo "IPS_CLASSIFICATION=$value" >> "${BDIR}/pkginfo"
;;
'org.opensolaris.consolidation')
echo "IPS_CONSOLIDATION=$value" >> "${BDIR}/pkginfo"
;;
'variant.arch'|'variant.opensolaris.zone'|'opensolaris.smf.fmri'|'org.opensolaris.smf.fmri'|'opensolaris.arc_url')
:
;;
'info.repository_changeset'|'info.maintainer_url'|'info.repository_url'|'info.defect_tracker.url'|'info.source_url'|'info.upstream_url'|'info.upstream')
:
;;
*)
echo "Unhandled set directive $name"
;;
esac
}
#
# handle dependencies. we only accept pkg fmris, ignore consolidations
# we could put the version information in, but need to decide if and how
# to use it before doing so
#
# if we hit an incorporate dependency then this is an incorporation
# and we simply bail
#
handle_depend() {
for frag in "$*"
do
eval "$frag"
done
case $type in
'incorporate')
echo "Looks like an incorporation, bailing out"
bail_out
;;
'require')
case $fmri in
pkg*)
pkg_str=`echo $fmri | sed 's=^pkg:/=='`
pkg_name=`echo $pkg_str | awk -F@ '{print $1}'`
pkg_vers=`echo $pkg_str | awk -F@ '{print $2}'`
case $pkg_name in
*incorporation)
:
;;
*)
svr4_name=`$PNAME $pkg_name`
init_depend
echo "P $svr4_name" >> "${BDIR}/install/depend"
;;
esac
;;
*consolidation*)
:
;;
*)
svr4_name=`$PNAME $fmri`
init_depend
echo "P $svr4_name" >> "${BDIR}/install/depend"
;;
esac
;;
*)
echo "Unhandled dependency type $type"
;;
esac
}
#
# transform to replace a pathname in this package
#
# we look for an architecture-specific and a generic replacement
# in the transforms hierarchy
#
transform_replace() {
filepath=$1
if [ -f "${BDIR}/${filepath}" ]; then
if [ -f "${TRANSDIR}/$filepath.${ARCH32}" ]; then
cp "${TRANSDIR}/$filepath.${ARCH32}" "${BDIR}/${filepath}"
elif [ -f "${TRANSDIR}/$filepath" ]; then
cp "${TRANSDIR}/$filepath" "${BDIR}/${filepath}"
else
echo "WARN: transform_replace cannot find replacement for ${filepath}"
fi
else
echo "WARN: transform_replace cannot find path ${filepath}"
fi
}
#
# transform to add a dependency
#
transform_depend() {
pkgdep=$1
init_depend
echo "P ${pkgdep}" >> "${BDIR}/install/depend"
}
#
# transform to remove a dependency
#
transform_undepend() {
pkgdep=$1
if [ -f "${BDIR}/install/depend" ]; then
mv "${BDIR}/install/depend" "${BDIR}/install/depend.transform"
cat "${BDIR}/install/depend.transform" | egrep -v "P ${pkgdep}\$" > "${BDIR}/install/depend"
rm "${BDIR}/install/depend.transform"
fi
}
#
# transform to delete a pathname from this package
#
# we need to remove the file from our temporary area and from
# the prototype file
#
transform_delete() {
filepath=$1
if [ -f "${BDIR}/${filepath}" ]; then
/usr/bin/rm -f "${BDIR}/${filepath}"
else
echo "WARN: transform_delete cannot find path ${filepath}"
fi
/usr/bin/mv "${BDIR}/prototype" "${BDIR}/prototype.transform"
cat "${BDIR}/prototype.transform" | grep -v " ${filepath}=${filepath} " > "${BDIR}/prototype"
/usr/bin/rm "${BDIR}/prototype.transform"
}
#
# transform to change the ftype of a pathname from this package
# need to have the class set to match
#
transform_type() {
filepath=$1
newtype=$2
if [ -f "${BDIR}/${filepath}" ]; then
/usr/bin/mv "${BDIR}/prototype" "${BDIR}/prototype.transform"
cat "${BDIR}/prototype.transform" | grep " ${filepath}=${filepath} " | read otype oclass opath operm ouser ogroup
cat "${BDIR}/prototype.transform" | grep -v " ${filepath}=${filepath} " > "${BDIR}/prototype"
case $newtype in
e)
oclass="preserve"
;;
*)
oclass="none"
;;
esac
echo "${newtype} ${oclass} ${opath} ${operm} ${ouser} ${ogroup}" >> "${BDIR}/prototype"
/usr/bin/rm "${BDIR}/prototype.transform"
else
echo "WARN: transform_type cannot find $filepath"
fi
}
#
# transform to rename a pathname in this package
#
transform_rename() {
filepath=$1
newpath=$2
newdir=`dirname $newpath`
echo "DBG: rename $filepath to $newpath in $newdir"
if [ -f "${BDIR}/${filepath}" ]; then
/usr/bin/mkdir -p "${BDIR}/${newdir}"
/usr/bin/mv "${BDIR}/${filepath}" "${BDIR}/${newpath}"
/usr/bin/mv "${BDIR}/prototype" "${BDIR}/prototype.transform"
cat "${BDIR}/prototype.transform" | grep " ${filepath}=${filepath} " | read otype oclass opath operm ouser ogroup
cat "${BDIR}/prototype.transform" | grep -v " ${filepath}=${filepath} " > ${BDIR}/prototype
echo "${otype} ${oclass} ${newpath}=${newpath} ${operm} ${ouser} ${ogroup}" >> ${BDIR}/prototype
/usr/bin/rm "${BDIR}/prototype.transform"
else
echo "WARN: transform_rename cannot find $filepath"
fi
}
#