-
Notifications
You must be signed in to change notification settings - Fork 7
/
pp.back.deb
631 lines (548 loc) · 16.4 KB
/
pp.back.deb
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
# Debian backend
# http://www.debian.org/doc/debian-policy/
# http://www.debian.org/doc/manuals/reference/ch-package.en.html
pp_platforms="$pp_platforms deb"
#@ pp_backend_deb_detect(uname_s): return true if matches uname on deb
pp_backend_deb_detect () {
test -f /etc/debian_version
}
#@ pp_deb_cmp_full_name(component hyphen): translate cpt into a Debian pkg name
pp_deb_cmp_full_name () {
local prefix
prefix="${pp_deb_name:-$name}"
case "$1" in
run) echo "${prefix}" ;;
dbg) echo "${prefix}-${pp_deb_dbg_pkgname}";;
dev) echo "${prefix}-${pp_deb_dev_pkgname}";;
doc) echo "${prefix}-${pp_deb_doc_pkgname}";;
*) pp_error "unknown component '$1'";
esac
}
#@ pp_backend_deb_init(): initialises platform variables for deb
pp_backend_deb_init () {
pp_deb_dpkg_version="2.0"
pp_deb_name=
pp_deb_version=
pp_deb_release=
pp_deb_arch=
pp_deb_arch_std=
pp_deb_maintainer="One Identity LLC <support@oneidentity.com>"
pp_deb_copyright=
pp_deb_distro=
pp_deb_control_description=
pp_deb_summary=
pp_deb_description=
pp_deb_dbg_pkgname="dbg"
pp_deb_dev_pkgname="dev"
pp_deb_doc_pkgname="doc"
pp_deb_section=contrib # Free software that depends on non-free software
# Detect the host architecture
pp_deb_detect_arch
# Make sure any programs we require are installed
pp_deb_check_required_programs
}
#@ pp_deb_check_required_programs(): looks for required programs
pp_deb_check_required_programs () {
local p needed notfound ok
needed= notfound=
for prog in dpkg dpkg-deb install md5sum fakeroot
do
if command -v $prog 2>/dev/null >/dev/null; then
pp_debug "$prog: found"
else
pp_debug "$prog: not found"
case "$prog" in
dpkg|dpkg-deb) p=dpkg;;
install|md5sum) p=coreutils;;
fakeroot) p=fakeroot;;
*) pp_die "unexpected dpkg tool $prog";;
esac
notfound="$notfound $prog"
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_deb_munge_description()<file: converts the description to a format that
# is control file friendly
pp_deb_munge_description () {
# Insert a leading space on each line, replace blank lines with a
#space followed by a full-stop.
pp_deb_control_description="`echo ${pp_deb_description:-$description} | \
sed 's,^\(.*\)$, \1, ' | sed 's,^[ \t]*$, .,g' | fmt -w 80`"
}
#@ pp_deb_detect_arch: sets pp_deb_arch, pp_deb_arch_std
pp_deb_detect_arch () {
pp_deb_arch=`dpkg-architecture -qDEB_HOST_ARCH`
pp_deb_arch_std=`uname -m`
}
# Strip invalid characters from a version number
# Described by Debian policy section 5.6.12
pp_deb_sanitize_version() {
echo "$@" | tr -d -c '[:alnum:].+-:~'
}
# Print the package version (based on either pp_deb_version or version)
# where all invalid characters have been stripped.
pp_deb_version_final() {
if test -n "$pp_deb_version"; then
# Don't sanitize; assume the user is sane (hah!)
echo "$pp_deb_version"
else
pp_deb_sanitize_version "$version"
fi
}
#@ pp_deb_conflict() < %conflict: generate Conflicts rules
pp_deb_conflict () {
local _name _vers _conflicts
_conflicts="Conflicts:"
while read _name _vers; do
case "$_name" in ""| "#"*) continue ;; esac
_conflicts="$_conflicts $_name"
test -n "$_vers" && _conflicts="$_conflicts $_name (>= $vers)"
_conflicts="${_conflicts},"
done
echo "${_conflicts%,}"
}
#@ pp_deb_make_control(cmp) > control: creates a debian control file
pp_deb_make_control() {
local cmp="$1"
local installed_size
# compute the installed size
installed_size=`pp_deb_files_size < $pp_wrkdir/%files.$cmp`
package_name=`pp_deb_cmp_full_name "$cmp"`
cat <<-.
Package: ${package_name}
Version: `pp_deb_version_final`-${pp_deb_release:-1}
Section: ${pp_deb_section:-contrib}
Priority: optional
Architecture: ${pp_deb_arch}
Maintainer: ${pp_deb_maintainer:-$maintainer}
Description: ${pp_deb_summary:-$summary}
${pp_deb_control_description}
Installed-Size: ${installed_size}
.
if test -s $pp_wrkdir/%depend."$cmp"; then
sed -ne '/^[ ]*$/!s/^[ ]*/Depends: /p' \
< $pp_wrkdir/%depend."$cmp"
fi
if test -s $pp_wrkdir/%conflict."$cmp"; then
pp_deb_conflict < $pp_wrkdir/%conflict."$cmp"
fi
}
#@ pp_deb_make_md5sums(data_dir file...) create md5sums for data files.
# files are relative to $data_dir
pp_deb_make_md5sums() {
local cmp="$1"; shift
local pkg_dir
pkg_dir=$pp_wrkdir/`pp_deb_cmp_full_name $cmp`
(cd $pkg_dir && md5sum "$@") > $pkg_dir/DEBIAN/md5sums ||
pp_error "cannot make md5sums"
}
#@ pp_deb_make_package_maintainer_script(output, source, description):
# create package maintainer script
pp_deb_make_package_maintainer_script() {
local output="$1"
local source="$2"
local desc="$3"
# See if we need to create this script at all
if [ -s "$source" ]
then
# Create header
cat <<-. >$output || pp_error "Cannot create $output"
#!/bin/sh
# $desc
# Generated by PolyPackage $pp_version
.
cat $source >> "$output" || pp_error "Cannot append to $output"
# Set perms
chmod 755 "$output" || pp_error "Cannot chmod $output"
fi
}
#@ pp_deb_handle_services(): handle services and append appropriate stuff
# to postinst/prerm
pp_deb_handle_services() {
local svc
#-- add service start/stop code
if test -n "$pp_services"; then
#-- append common %post install code
pp_systemd_service_install_common >> $pp_wrkdir/%post.run
#-- record the uninstall commands in reverse order
for svc in $pp_services; do
pp_load_service_vars $svc
# Create init script and systemd service file (unless they exists)
pp_deb_service_make_service_files $svc ||
pp_error "could not create service files for $svc"
#-- append %post code to install the svc
test x"yes" = x"$enable" &&
cat<<-. >> $pp_wrkdir/%post.run
case "\$1" in
configure)
# Install the service links
_pp_systemd_init
if test -n "\$systemctl_cmd"; then
_pp_systemd_install $svc
_pp_systemd_enable $svc
else
update-rc.d $svc defaults
fi
;;
esac
.
#-- prepend %preun code to stop svc
cat<<-. | pp_prepend $pp_wrkdir/%preun.run
case "\$1" in
remove|deconfigure|upgrade)
# Stop the $svc service
invoke-rc.d $svc stop
_pp_systemd_disable $svc
;;
esac
.
#-- prepend %postun code to remove service
cat<<-. | pp_prepend $pp_wrkdir/%postun.run
case "\$1" in
purge)
# Remove the service links
update-rc.d $svc remove
_pp_systemd_remove $svc
;;
esac
.
done
pp_systemd_service_remove_common | pp_prepend $pp_wrkdir/%preun.run
#pp_deb_service_remove_common | pp_prepend $pp_wrkdir/%preun.run
# Actual systemd service removal is done in %postun.
# Otherwise, systemd may pick up the init.d script if it exists.
pp_systemd_service_remove_common | pp_prepend $pp_wrkdir/%postun.run
fi
}
#@ pp_deb_fakeroot(): runs fakeroot with the current savefile
pp_deb_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_deb_files_size() < %files: estimate installed disk usage in kB
pp_deb_files_size () {
local t m o g f p st
while read t m o g f p st; do
case $t in
f|s) du -k "${pp_destdir}$p";;
d) echo 4;;
esac
done | awk '{n+=$1} END {print n}'
}
#@ pp_deb_make_DEBIAN(): create control files
pp_deb_make_DEBIAN() {
local cmp="${1:-run}"
local data cmp_full_name
local old_umask
old_umask=`umask`
umask 0022
cmp_full_name=`pp_deb_cmp_full_name $cmp`
data=$pp_wrkdir/$cmp_full_name
# Create DEBIAN dir $data/DEBIAN
mkdir -p $data/DEBIAN
# Create control file
pp_deb_make_control $cmp > $data/DEBIAN/control
# Copy in conffiles
if test -f $pp_wrkdir/%conffiles.$cmp; then
cp $pp_wrkdir/%conffiles.$cmp $data/DEBIAN/conffiles
fi
# Create preinst
pp_deb_make_package_maintainer_script "$data/DEBIAN/preinst" \
"$pp_wrkdir/%pre.$cmp" "Pre-install script for $cmp_full_name"\
|| exit $?
# Create postinst
pp_deb_make_package_maintainer_script "$data/DEBIAN/postinst" \
"$pp_wrkdir/%post.$cmp" "Post-install script for $cmp_full_name"\
|| exit $?
# Create prerm
pp_deb_make_package_maintainer_script "$data/DEBIAN/prerm" \
"$pp_wrkdir/%preun.$cmp" "Pre-uninstall script for $cmp_full_name"\
|| exit $?
# Create postrm
pp_deb_make_package_maintainer_script "$data/DEBIAN/postrm" \
"$pp_wrkdir/%postun.$cmp" "Post-uninstall script for $cmp_full_name"\
|| exit $?
umask $old_umask
}
#@ pp_deb_make_data(name): Package up data files for .deb
pp_deb_make_data() {
local _l t m o g f p st data
local data share_doc owner group
cmp=$1
data=$pp_wrkdir/`pp_deb_cmp_full_name $cmp`
cat $pp_wrkdir/%files.${cmp} | while read t m o g f p st; do
if test x"$m" = x"-"; then
case "$t" in
d) m=755;;
f) m=644;;
esac
fi
test x"$o" = x"-" && o=root
test x"$g" = x"-" && g=root
case "$t" in
f) # Files
pp_deb_fakeroot install -D -o $o -g $g -m ${m} $pp_destdir/$p $data/$p;
case "$f" in
*v*)
# File marked as "volatile". Assume this means it's a conffile
# TODO: check this as admins like modified conffiles to be left
# behind
echo "$p" >> $pp_wrkdir/%conffiles.$cmp
;;
esac
;;
d) # Directories
pp_deb_fakeroot install -m ${m} -o $o -g $g -d $data/$p;;
s) # Symlinks
# Remove leading / from vars
rel_p=`echo $p | sed s,^/,,`
rel_st=`echo $st | sed s,^/,,`
# TODO: we are always doing absolute links here. We should follow
# the debian policy of relative links when in the same top-level
# directory
(cd $data; ln -sf $st $rel_p);;
*) pp_error "Unsupported data file type: $t";;
esac
done
# If no copyright file is present add one. This is a debian requirement.
share_doc="/usr/share/doc/`pp_deb_cmp_full_name $cmp`"
if [ ! -f "$data/$share_doc/copyright" ]
then
echo "${pp_deb_copyright:-$copyright}" > "$pp_wrkdir/copyright"
install -D -m 644 "$pp_wrkdir/copyright" "$data/$share_doc/copyright"
fi
}
#@ pp_deb_makedeb(component): creates directory structure ready for dpkg-deb
pp_deb_makedeb () {
local cmp
local package_build_dir
cmp="$1"
package_build_dir=$pp_wrkdir/`pp_deb_cmp_full_name $cmp`
# Create package dir
mkdir -p $package_build_dir
# Copy in data
pp_deb_make_data $cmp ||
pp_die "Could not make DEBIAN data files for $cmp"
# Make control files
# must be done after copying data so conffiles are found
pp_deb_make_DEBIAN $cmp ||
pp_die "Could not make DEBIAN control files for $cmp"
# Create md5sums
pp_deb_make_md5sums $cmp `(cd $package_build_dir;
find . -name DEBIAN -prune -o -type f -print | sed "s,^\./,,")` ||
pp_die "Could not make DEBIAN md5sums for $cmp"
}
#@ pp_backend_deb(): processes output files to generate a package files
pp_backend_deb () {
local debname
# Munge description for control file inclusion
pp_deb_munge_description
# Handle services
pp_deb_handle_services $cmp
for cmp in $pp_components
do
debname=`pp_deb_name $cmp`
pp_deb_makedeb $cmp
done
. $pp_wrkdir/%fixup
for cmp in $pp_components
do
debname=`pp_deb_name $cmp`
# Create debian package
pp_debug "Building `pp_deb_cmp_full_name $cmp` -> $output"
pp_deb_fakeroot dpkg-deb \
--build $pp_wrkdir/`pp_deb_cmp_full_name $cmp` \
$pp_wrkdir/$debname ||
pp_error "failed to create $cmp package"
done
}
#@ pp_backend_deb_cleanup(): removes any files created outside $pp_wrkdir
pp_backend_deb_cleanup () {
# rm -rf $pp_wrkdir
:
}
#@ pp_deb_name(component): prints the names of the package files
pp_deb_name () {
local cmp="${1:-run}"
echo `pp_deb_cmp_full_name $cmp`"_"`pp_deb_version_final`"-${pp_deb_release:-1}_${pp_deb_arch}.deb"
}
#
#@ pp_backend_deb_names: prints the names of the package files
pp_backend_deb_names () {
for cmp in $pp_components
do
pp_deb_name $cmp
done
}
#@ pp_backend_deb_install_script(): generate a helper install script
pp_backend_deb_install_script () {
local 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_deb_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_deb_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
dpkg --install \`cmp_to_pathname "\$@"\`
;;
uninstall)
test \$# -ge 1 || usage \$op
dpkg --remove \`cmp_to_pkgname "\$@"\`; :
;;
start|stop)
test \$# -ge 1 || usage \$op
ec=0
for svc
do
/etc/init.d/\$svc \$op || ec=1
done
exit \$ec
;;
print-platform)
test \$# -eq 0 || usage \$op
echo "linux-${pp_deb_arch}"
;;
*)
usage
;;
esac
.
}
#@ pp_backend_deb_probe(): output local platform's short id
pp_backend_deb_probe() {
local arch distro release
pp_deb_detect_arch
# /etc/debian_version exists on Debian & Ubuntu, so it's no use
# to us. Use lsb_release instead.
case `(lsb_release -is || echo no-lsb) 2>/dev/null` in
Debian)
distro=deb
;;
Ubuntu)
distro=ubu
;;
no-lsb)
echo unknown-$pp_deb_arch_std
return 0
;;
*)
distro=unknown
;;
esac
release=`lsb_release -rs`
# If release is not numeric, use the codename
case $release in
*[!.0-9r]*)
release=`lsb_release -cs`
case $release in
buzz)
release="11"
;;
rex)
release="12"
;;
bo)
release="13"
;;
hamm)
release="20"
;;
slink)
release="21"
;;
potato)
release="22"
;;
woody)
release="30"
;;
sarge)
release="31"
;;
etch)
release="40"
;;
lenny)
release="50"
;;
squeeze)
release="60"
;;
wheezy)
release="70"
;;
jessie)
release="80"
;;
stretch)
release="90"
;;
esac
;;
*)
# Remove trailing revision number and any dots
release=`echo $release | cut -dr -f1 | tr -d .`
;;
esac
echo $distro$release-$pp_deb_arch_std
}
#@ pp_backend_deb_vas_platforms(): print the VAS platform identifiers
pp_backend_deb_vas_platforms () {
case "$pp_deb_arch_std" in
x86_64) echo "linux-x86_64.deb";; # DO NOT add linux-x86.deb here!!
*86) echo "linux-x86.deb";;
*) pp_die "unknown architecture ${pp_deb_arch_std}";;
esac
}