-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpp.back.bsd
597 lines (515 loc) · 18.3 KB
/
pp.back.bsd
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
#
# FreeBSD backend
#
# https://wiki.freebsd.org/pkgng
#
#
# Add bsd to the list of platforms to be considered
pp_platforms="$pp_platforms bsd"
#@ pp_bsd_munge_text: Fixes the text so the pkg create won't complain
pp_bsd_munge_text () {
# Insert a leading space on each line, replace blank lines with a
#space followed by a full-stop.
test -z "$1" && pp_die "pp_bsd_munge_text requires a parameter"
echo ${1} | sed "s,^\(.*\)$, \1, " | sed "s,^[ \t]*$, .,g"
}
#@ pp_backend_bsd_detect(): return true if this platform uses FreeBSD pkgs
pp_backend_bsd_detect () {
test x"$1" = x"FreeBSD" -o x"$1" = x"DragonFly"
}
#@ pp_backend_bsd_init(): initialize the bsd vars
pp_backend_bsd_init () {
# Get the OS revision
pp_bsd_detect_os
# Get the arch (i386/x86_64)
pp_bsd_detect_arch
pp_bsd_name=
pp_bsd_version=
pp_bsd_origin=
pp_bsd_comment=
pp_bsd_arch=
pp_bsd_abi=
pp_bsd_www=
pp_bsd_maintainer=
pp_bsd_prefix="/usr/local/"
pp_bsd_desc=
pp_bsd_message=
# Newer "pkg" (>=1.17.0) generates package.pkg, before that package.txz.
if pp_is_version_greater 1.17.0 "$(pkg --version)"; then
pp_bsd_pkg_sfx=pkg
else
pp_bsd_pkg_sfx=txz
fi
# pp_bsd_category must be in array format comma separated
# pp_bsd_category=[security,network]
pp_bsd_category=
# pp_bsd_licenselogic can be one of the following: single, and, or unset
pp_bsd_licenselogic=
# pp_bsd_licenses must be in array format comma separated
# pp_bsd_licenses=[GPLv2,MIT]
pp_bsd_licenses=
# pp_bsd_annotations. These can be any key: value pair
# key must be separated by a :
# keyvalue pairs must be comma separated
# pp_bsd_annotations="repo_type: binary, somekey: somevalue"
# since all packages created by PolyPackage will be of type binary
# let's just set it now.
pp_bsd_annotations="repo_type: binary"
pp_bsd_dbg_pkgname="debug"
pp_bsd_dev_pkgname="devel"
pp_bsd_doc_pkgname="doc"
# Make sure any programs we require are installed
pp_bsd_check_required_programs
}
#@ pp_bsd_cmp_full_name(cmp):
pp_bsd_cmp_full_name () {
typeset prefix
prefix="${pp_bsd_name:-$name}"
case "$1" in
run) echo "${prefix}" ;;
dbg) echo "${prefix}-${pp_bsd_dbg_pkgname}";;
dev) echo "${prefix}-${pp_bsd_dev_pkgname}";;
doc) echo "${prefix}-${pp_bsd_doc_pkgname}";;
*) pp_error "unknown component '$1'";
esac
}
#@ pp_bsd_check_required_programs(): looks for required programs
pp_bsd_check_required_programs () {
local p needed notfound ok
needed= notfound=
# list of programs FreeBSD needs in order to create a binary package
for prog in ${pp_bsd_required_programs:-"pkg"}
do
if command -v $prog 2>&1 > /dev/null; then
pp_debug "$prog: found"
else
pp_debug "$prog: not found"
case "$prog" in
pkg) p=pkg;;
*) pp_die "Unexpected pkg tool $prog";;
esac
notfound="$notfound $prod"
pp_contains "$needed" "$p" || needed="$needed $p"
fi
done
if [ -n "$notfound" ]; then
pp_error "cannot find these programs: $notfound"
pp_error "please install these packages: $needed"
fi
}
#@pp_bsd_detect_os: sets pp_bsd_os and pp_bsd_os_rev
pp_bsd_detect_os () {
typeset revision
pp_bsd_os=`uname -s`
revision=`uname -r`
pp_bsd_os_rev=`echo $revision | awk -F '-' '{print $1}'`
}
#@ pp_bsd_detect_arch: sets pp_bsd_platform, pp_bsd_platform_std
pp_bsd_detect_arch() {
pp_bsd_platform="`uname -m`"
case $pp_bsd_platform in
amd64|x86_64) pp_bsd_platform_std=x86_64;;
i386) pp_bsd_platform_std=i386;;
*) pp_bsd_platform_std=unknown;;
esac
}
#@ pp_bsd_label(arg) writes a label in format of label
pp_bsd_label () {
local label arg
label="$1"; shift
for arg
do
test -z "$arg" || echo "$label: $arg"
done
}
#@ pp_bsd_make_annotations(manifest): Annotations are freeform tag-value pairs.
#@ pp_bsd_annotations should be in the form of: "key:value, key:value, ..."
#@ see man pkg-annotate(8)
pp_bsd_make_annotations () {
test -z $1 && pp_die "pp_bsd_make_annotations requires a parameter"
manifest=$1
# Add annotations. These can be any key: value pair
# key must be separated by a :
# key:value pairs must be comma separated.
if test -n "$pp_bsd_annotations"; then
pp_debug "Processing annotations:"
pp_bsd_label "annotations" "{" >> $manifest
SAVEIFS=$IFS
IFS=,
for annotate in $pp_bsd_annotations; do
# Remove any spaces at the start of the line
annotate=`echo $annotate | sed 's/^ *//'`
pp_debug " $annotate"
echo " $annotate" >> $manifest
done
IFS=$SAVEIFS
echo "}" >> $manifest
fi
}
#@ pp_bsd_make_depends(cmp manifest): convert %depends into pkg deps
pp_bsd_make_depends() {
typeset package origin version
cmp=$1
manifest=$2
if test -s $pp_wrkdir/%depend.${cmp}; then
echo "deps: {" >> $manifest
cat $pp_wrkdir/%depend.${cmp} | while read package origin version; do
if test x != x$package; then
pp_debug "Processing dependency: $package"
if test x != x$origin -a x != x$version; then
pp_debug " $package: {origin: \"$origin\", version: \"$version\"}"
echo " $package: {origin: \"$origin\", version: \"$version\"}" >> $manifest
else
pp_warn "Dependency $package is missing origin or version or both"
fi
fi
done
echo "}" >> $manifest
fi
}
#@ pp_bsd_make_messages(manifest): convert pp_bsd_message or pp_bsd_messages[1..n] into pkg manifest format
#@ For a single message use pp_bsd_message
#@ pp_bsd_message="message"
#@ For multiple messages use pp_bsd_message[1..n]
#@ pp_bsd_messages1="message 1"
#@ pp_bsd_messages2="message 2"
#@ pp_bsd_messages[3..n]="message [3..n]
#@
#@ In the case where both pp_bsd_message and pp_bsd_messages[1..n] are supplied treat pp_bsd_message as pp_bsd_messages0
#@
pp_bsd_make_messages () {
test -z $1 && pp_die "pp_bsd_make_messages requires a parameter"
manifest=$1
pp_debug "Processing messages"
# Empty messages: [ ] is OK in the manifest
pp_bsd_label "messages" "[" >> $manifest
# Look for a single message in the variable pp_bsd_message
if test -n "$pp_bsd_message"; then
echo " { message: \"`pp_bsd_munge_text "$pp_bsd_message"`\" }," >> $manifest
fi
local a=1
# Look for messages in the variables pp_bsd_message_[1..n]
var="pp_bsd_messages_1"
while [ -n "${!var}" ]; do
echo " { message: \"`pp_bsd_munge_text "${!var}"`\" }," >> $manifest
a=`expr $a + 1`
var="pp_bsd_messages_$a"
done
echo "]" >> $manifest
}
#@ pp_bsd_make_manifest(cmp manifest): creates a pkg manifest file
pp_bsd_make_manifest() {
local cmp manifest
cmp="$1"
manifest="$2"
package_name=`pp_bsd_cmp_full_name $cmp`
# Required for pkg +MANIFEST
cat <<-. >> $manifest
name: "${package_name}"
version: "${pp_bsd_version:-$version}"
origin: "${pp_bsd_origin}"
www: "${pp_bsd_www}"
desc: "`pp_bsd_munge_text "${pp_bsd_desc:-$description}"`"
comment: "${pp_bsd_comment:-$summary}"
maintainer: "${pp_bsd_maintainer}"
prefix: "${pp_bsd_prefix}"
.
# Optional, so if they are not included in the pkg-product.pp file then do not create the label
pp_bsd_label "categories" "${pp_bsd_categories}" >> $manifest
pp_bsd_label "arch" "${pp_bsd_arch}" >> $manifest
pp_bsd_label "abi" "${pp_bsd_abi}" >> $manifest
pp_bsd_label "licenselogic" "${pp_bsd_licenselogic}" >> $manifest
pp_bsd_label "licenses" "${pp_bsd_licenses}" >> $manifest
pp_bsd_make_annotations $manifest
pp_bsd_make_depends $cmp $manifest
pp_bsd_make_messages $manifest
}
#@ pp_bsd_fakeroot(): run a command in an environment faking root privs for file manipulation
pp_bsd_fakeroot () {
if test -s $pp_wrkdir/fakeroot.save; then
fakeroot -i $pp_wrkdir/fakeroot.save -s $pp_wrkdir/fakeroot.save "$@"
else
fakeroot -s $pp_wrkdir/fakeroot.save "$@"
fi
}
#@ pp_bsd_make_data(component): convert %file.$cmp to the correct output for pkg creation: cmp
pp_bsd_make_data() {
# t = file type
# m = file mode
# o = file owner
# g = file group
# f = ?
# p = file path
# st = file link
#
# EXAMPLE: f 755 root httpd v /usr/bin/hello goodbye
# -> /usr/bin/hello: {uname: root, gname: httpd, perm: 755 } goodbye
typeset _l t m o g f p st datadir
cmp=$1
datadir=$pp_wrkdir/`pp_bsd_cmp_full_name $cmp`
local path
outfilelist="$pp_wrkdir/files.list.$cmp"
outdirslist="$pp_wrkdir/dirs.list.$cmp"
pp_debug "Processing $pp_wrkdir/%file.${cmp}"
echo "files: {" > $outfilelist
echo "directories: {" > $outdirslist
cat $pp_wrkdir/%files.${cmp} | while read t m o g f p st; do
test x"$o" = x"-" && o="${pp_bsd_defattr_uid:-root}"
test x"$g" = x"-" && g="${pp_bsd_defattr_gid:-wheel}"
if test x"$m" = x"-"; then
case "$t" in
d) m=755;;
f) m=644;;
esac
fi
path=$p
case "$t" in
f) # Files
case "$f" in
*v*)
# For now just skip the file if it is volatile, we
# will need to remove it in the pre uninstall script
pp_warn "file $path was marked as volatile, skipping"
;;
*)
# If the directory doesn't exist where we are going to copy this file, then create it first
if [ ! -d `dirname "$datadir$path"` ]; then
pp_debug "creating directory `dirname "$datadir$path"`"
mkdir -p `dirname "$datadir$path"`
fi
pp_debug "install -D $datadir -o $o -g $g -m ${m} -v $pp_destdir$p $datadir$path"
pp_bsd_fakeroot install -D $datadir -o $o -g $g -m ${m} -v $pp_destdir$p $datadir$path
echo " \"$path\": \"-\", \"$path\": {uname: $o, gname: $g, perm: ${m}}" >> $outfilelist
;;
esac
;;
d) # Directories
pp_debug "install -D $datadir -o $o -g $g -m ${m} -d -v $datadir$path";
pp_bsd_fakeroot install -D $datadir -o $o -g $g -m ${m} -d -v $datadir$path;
echo " \"$path\": \"-\", \"$path\": {uname: $o, gname: $g, perm: ${m}}" >> $outdirslist;
;;
s) # Symlinks
pp_debug "Found symlink: $datadir$path";
# Remove leading /
rel_p=`echo $p | sed s,^/,,`
(cd $datadir; ln -sf $st $rel_p);
# Do we care if the file doesn't exist? Just symnlink it regardless and throw a warning? This will be important in the case
# where we depend on other packages to be installed and will be using the libs from that package.
if [ ! -e "$datadir$path" ]; then
pp_warn "$datadir$path does not exist"
fi
echo " \"$path\": \"$st\"" >> $outfilelist;
;;
*) pp_error "Unsupported data file type: %t";;
esac
done
echo "}" >> $outfilelist
echo "}" >> $outdirslist
cat $outfilelist >> $manifest
cat $outdirslist >> $manifest
pp_debug "Finished processing $pp_wrkdir/%file.${cmp}"
}
#@ pp_bsd_makebsd(component): creates directory structure reeady for pkg create
pp_bsd_makebsd() {
typeset cmp
typeset package_build_dir
local manifest postinstall preinstall preuninstall postuninstall preupgrade postupgrade
cmp="$1"
if test -z "$pp_bsd_platform"; then
pp_error "Unknown BSD architecture"
return 1
fi
_subname=`pp_bsd_cmp_full_name $cmp`
package_build_dir=$pp_wrkdir/$_subname
manifest="$package_build_dir/+MANIFEST"
postinstall="$package_build_dir/+POST_INSTALL"
preinstall="$package_build_dir/+PRE_INSTALL"
preuninstall="$package_build_dir/+PRE_DEINSTALL"
postuninstall="$package_build_dir/+POST_DEINSTALL"
preupgrade="$package_build_dir/+PRE_UPGRADE"
postupgrade="$package_build_dir/+POST_UPGRADE"
# Create package dir
mkdir -p $package_build_dir
pp_bsd_make_manifest $cmp $manifest
pp_bsd_make_data $cmp
pp_debug "Processing pre/post install scripts"
if test -s $pp_wrkdir/%pre.$cmp; then
pp_debug "Found %pre.$cmp"
{
cat "$pp_wrkdir/%pre.$cmp"
} > $preinstall
pp_debug "Created $preinstall"
fi
if test -s $pp_wrkdir/%post.$cmp; then
pp_debug "Found %post.$cmp"
{
echo "# Post install script for "
cat "$pp_wrkdir/%post.$cmp"
} > $postinstall
pp_debug "Created $postinstall"
fi
pp_debug "Processing pre/post uninstall scripts"
if test -s $pp_wrkdir/%preun.$cmp; then
pp_debug "Found %preun.$cmp"
{
echo "# Pre uninstall script for ${pp_bsd_name:-$name}"
cat "$pp_wrkdir/%preun.$cmp"
} > $preuninstall
pp_debug "Created pkg $preuninstall"
fi
if test -s $pp_wrkdir/%postun.$cmp; then
pp_debug "Found %postun.$cmp"
{
echo "# Post uninstall script for ${pp_bsd_name:-$name}"
cat "$pp_wrkdir/%postun.$cmp"
} > $postuninstall
pp_debug "Created $postuninstall"
fi
if test -s $pp_wrkdir/%preup.$cmp; then
pp_debug "Found %preup.$cmp"
{
echo "# Pre upgrade script for ${pp_bsd_name:-$name}"
cat "$pp_wrkdir/%preup.$cmp"
} > $preupgrade
pp_debug "Created pkg $preupgrade"
fi
if test -s $pp_wrkdir/%postup.$cmp; then
pp_debug "Found %postup.$cmp"
{
echo "# Post upgrade script for ${pp_bsd_name:-$name}"
cat "$pp_wrkdir/%postup.$cmp"
} > $postupgrade
pp_debug "Created $postupgrade"
fi
}
pp_backend_bsd() {
#get-files-dir-entries
#create-manifest
#create-preuninstall
#create-postinstall
#create-package
#
pp_bsd_handle_services
for cmp in $pp_components
do
_subname=`pp_bsd_cmp_full_name $cmp`
pp_debug "Generating packaging specific files for $_subname"
pp_bsd_makebsd $cmp
done
# call this to fixup any files before creating the actual packages
. $pp_wrkdir/%fixup
for cmp in $pp_components
do
_subname=`pp_bsd_cmp_full_name $cmp`
package_build_dir=$pp_wrkdir/$_subname
# Build the actual packages now
pp_debug "Building FreeBSD $_subname"
pp_debug "Running package create command: pkg create -m $package_build_dir -r $pp_wrkdir/`pp_bsd_cmp_full_name $cmp` -o $pp_wrkdir"
pp_bsd_fakeroot pkg create -m $package_build_dir -r $pp_wrkdir/`pp_bsd_cmp_full_name $cmp` -o $pp_wrkdir -v
done
}
#@ pp_bsd_name(component): print the name of the FreeBSD package files
pp_bsd_name () {
typeset cmp="${1:-run}"
echo `pp_bsd_cmp_full_name $cmp`"-${pp_bsd_version:-$version}.${pp_bsd_pkg_sfx}"
}
#@ pp_backend_bsd_names(): print the names of the FreeBSD package files
pp_backend_bsd_names () {
for cmp in $pp_components; do
echo `pp_bsd_cmp_full_name $cmp`"-${pp_bsd_version:-$version}.${pp_bsd_pkg_sfx}"
done
}
#@ pp_backend_bsd_cleanup(): removes leftover files
pp_backend_bsd_cleanup () {
:
}
#@ pp_backend_bsd_probe(): print the local platform's short name
pp_backend_bsd_probe () {
echo "${pp_bsd_os}${pp_bsd_os_rev}-${pp_bsd_platform_std}"
}
#@ pp_backend_bsd_vas_platforms(): print the VAS platform identifiers
pp_backend_bsd_vas_platforms() {
case "${pp_bsd_platform_std}" in
x86_64) echo "FreeBSD-x86_64.${pp_bsd_pkg_sfx} FreeBSD-i386.${pp_bsd_pkg_sfx}";;
i386) echo "FreeBSD-i386.${pp_bsd_pkg_sfx}";;
*) pp_die "unknown architecture $pp_bsd_platform_std";;
esac
}
#@ pp_backend_bsd_install_script(); Generates an script to manipulate the created pkg.txz
pp_backend_bsd_install_script () {
typeset cmp _cmp_full_name
echo "#!/bin/sh"
pp_install_script_common
cat <<.
cmp_to_pkgname () {
test x"\$*" = x"all" && set -- $pp_components
for cmp
do
case \$cmp in
.
for cmp in $pp_components; do
echo " $cmp) echo '`pp_bsd_cmp_full_name $cmp`';;"
done
cat <<.
*) usage;;
esac
done
}
cmp_to_pathname () {
test x"\$*" = x"all" &&
set -- $pp_components
for cmp
do
case \$cmp in
.
for cmp in $pp_components; do
echo " $cmp) echo \${PP_PKGDESTDIR:-.}/'`pp_bsd_name $cmp`';;"
done
cat <<.
*) usage;;
esac
done
}
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
cmp_to_pathname "\$@"
;;
install)
test \$# -ge 1 || usage \$op
pkg add \`cmp_to_pathname "\$@"\`
;;
uninstall)
test \$# -ge 1 || usage \$op
pkg remove \`cmp_to_pkgname "\$@"\`; :
;;
start|stop)
test \$# -ge 1 || usage \$op
ec=0
for svc
do
/etc/rc.d/\$svc \$op || ec=1
done
exit \$ec
;;
print-platform)
test \$# -eq 0 || usage \$op
echo "${pp_bsd_os}-${pp_bsd_platform}"
echo '`pp_backend_bsd_probe`'
;;
*)
usage
;;
esac
.
}