-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpkg2zap
executable file
·83 lines (74 loc) · 1.67 KB
/
pkg2zap
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
#!/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 2024 Peter Tribble
#
#
# convert an svr4 package (in datastream format) into zap format
#
case $# in
2)
FPKG="$1"
BROOT="$2"
;;
*)
echo "Usage: $0 input_pkg output_dir"
exit 2
;;
esac
#
# Default locations
#
THOME=${THOME:-/packages/localsrc/Tribblix}
BUILD="${THOME}/build"
#
# sanity check
#
if [ ! -d "$BUILD" ]; then
echo "ERROR: unable to find build directory $BUILD"
exit 1
fi
if [ ! -f "$FPKG" ]; then
echo "ERROR: input file not found"
exit 1
fi
if [ ! -d "$BROOT" ]; then
echo "ERROR: output directory not found"
exit 1
fi
# FIXME: uncompress compressed packages
BPKG=${FPKG##*/}
TDIR=/tmp/pkg2zap.$(date '+%F-%T').$$
rm -fr "$TDIR"
mkdir -p "$TDIR"
pkgtrans "$FPKG" "$TDIR" all
cd "$TDIR" || exit 1
PNAME=${BPKG%.pkg}
# 7z gives us an extra 2-3% reduction in file size
#zip -9 -q -r ${BROOT}/${BPKG%.pkg}.zap *
7za a -tzip -mx=9 -mfb=256 "${BROOT}/${PNAME}.zap" *
chmod a+r "${BROOT}/${PNAME}.zap"
cd /
# pregenerate the md5 checksum ready for catalog creation
openssl md5 "${BROOT}/${PNAME}.zap" | /usr/bin/awk '{print $NF}' > "${BROOT}/${PNAME}.zap.md5"
# sign the zap file
"${BUILD}"/sign-file "${BROOT}/${PNAME}.zap"
#
# clean up
#
rm -fr "$TDIR"
ls -lh "${BROOT}/${PNAME}.zap"