1 | #!/bin/sh
|
---|
2 | # $Id: makepackage.sh 98685 2023-02-22 13:37:21Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # VirtualBox package creation script, Solaris hosts.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox base platform packages, as
|
---|
11 | # available from https://www.virtualbox.org.
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or
|
---|
14 | # modify it under the terms of the GNU General Public License
|
---|
15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
16 | # License.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful, but
|
---|
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | # General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | #
|
---|
26 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | #
|
---|
28 |
|
---|
29 | #
|
---|
30 | # Usage:
|
---|
31 | # makepackage.sh [--hardened] [--ips] [--without-VBoxBugReport] [--without-VBoxBalloonCtrl] \
|
---|
32 | # [--without-VBoxAutostart] [--without-vboxwebsrv] \
|
---|
33 | # $(PATH_TARGET)/install packagename {$(KBUILD_TARGET_ARCH)|neutral} $(VBOX_SVN_REV)
|
---|
34 |
|
---|
35 |
|
---|
36 | # Parse options.
|
---|
37 | HARDENED=""
|
---|
38 | IPS_PACKAGE=""
|
---|
39 | PACKAGE_SPEC="prototype"
|
---|
40 | OPT_WITHOUT_VBoxBugReport=""
|
---|
41 | OPT_WITHOUT_VBoxBalloonCtrl=""
|
---|
42 | OPT_WITHOUT_VBoxAutostart=""
|
---|
43 | OPT_WITHOUT_vboxwebsrv=""
|
---|
44 | while [ $# -ge 1 ];
|
---|
45 | do
|
---|
46 | case "$1" in
|
---|
47 | --hardened)
|
---|
48 | HARDENED=1
|
---|
49 | ;;
|
---|
50 | --ips)
|
---|
51 | IPS_PACKAGE=1
|
---|
52 | PACKAGE_SPEC="virtualbox.p5m"
|
---|
53 | ;;
|
---|
54 | --without-VBoxBugReport)
|
---|
55 | OPT_WITHOUT_VBoxBugReport="yes"
|
---|
56 | ;;
|
---|
57 | --without-VBoxBalloonCtrl)
|
---|
58 | OPT_WITHOUT_VBoxBalloonCtrl="yes"
|
---|
59 | ;;
|
---|
60 | --without-VBoxAutostart)
|
---|
61 | OPT_WITHOUT_VBoxAutostart="yes"
|
---|
62 | ;;
|
---|
63 | --without-vboxwebsrv)
|
---|
64 | OPT_WITHOUT_vboxwebsrv="yes"
|
---|
65 | ;;
|
---|
66 | *)
|
---|
67 | break
|
---|
68 | ;;
|
---|
69 | esac
|
---|
70 | shift
|
---|
71 | done
|
---|
72 |
|
---|
73 | if [ -z "$4" ]; then
|
---|
74 | echo "Usage: $0 installdir packagename x86|amd64 svnrev"
|
---|
75 | echo "-- packagename must not have any extension (e.g. VirtualBox-SunOS-amd64-r28899)"
|
---|
76 | exit 1
|
---|
77 | fi
|
---|
78 |
|
---|
79 | PKG_BASE_DIR="$1"
|
---|
80 | PACKAGE_SPEC="$PKG_BASE_DIR/$PACKAGE_SPEC"
|
---|
81 | VBOX_INSTALLED_DIR=/opt/VirtualBox
|
---|
82 | if [ -n "$IPS_PACKAGE" ]; then
|
---|
83 | VBOX_PKGFILE="$2".p5p
|
---|
84 | else
|
---|
85 | VBOX_PKGFILE="$2".pkg
|
---|
86 | fi
|
---|
87 | # VBOX_PKG_ARCH is currently unused.
|
---|
88 | VBOX_PKG_ARCH="$3"
|
---|
89 | VBOX_SVN_REV="$4"
|
---|
90 |
|
---|
91 | if [ -n "$IPS_PACKAGE" ] ; then
|
---|
92 | VBOX_PKGNAME=system/virtualbox
|
---|
93 | else
|
---|
94 | VBOX_PKGNAME=SUNWvbox
|
---|
95 | fi
|
---|
96 | # any egrep should do the job, the one from /usr/xpg4/bin isn't required
|
---|
97 | VBOX_EGREP=/usr/bin/egrep
|
---|
98 | # need dynamic regex support which isn't available in S11 /usr/bin/awk
|
---|
99 | VBOX_AWK=/usr/xpg4/bin/awk
|
---|
100 |
|
---|
101 | # bail out on non-zero exit status
|
---|
102 | set -e
|
---|
103 |
|
---|
104 | if [ -n "$IPS_PACKAGE" ]; then
|
---|
105 |
|
---|
106 | package_spec_create()
|
---|
107 | {
|
---|
108 | > "$PACKAGE_SPEC"
|
---|
109 | }
|
---|
110 |
|
---|
111 | package_spec_append_info()
|
---|
112 | {
|
---|
113 | : # provided by vbox-ips.mog
|
---|
114 | }
|
---|
115 |
|
---|
116 | package_spec_append_content()
|
---|
117 | {
|
---|
118 | rm -rf "$1/vbox-repo"
|
---|
119 | pkgsend generate "$1" | pkgfmt >> "$PACKAGE_SPEC"
|
---|
120 | }
|
---|
121 |
|
---|
122 | package_spec_append_hardlink()
|
---|
123 | {
|
---|
124 | if [ -f "$3$4/amd64/$2" -o -f "$3$4/i386/$2" ]; then
|
---|
125 | echo "hardlink path=$4/$2 target=$1" >> "$PACKAGE_SPEC"
|
---|
126 | fi
|
---|
127 | }
|
---|
128 |
|
---|
129 | package_spec_fixup_content()
|
---|
130 | {
|
---|
131 | :
|
---|
132 | }
|
---|
133 |
|
---|
134 | package_create()
|
---|
135 | {
|
---|
136 | VBOX_DEF_HARDENED=
|
---|
137 | [ -z "$HARDENED" ] && VBOX_DEF_HARDENED='#'
|
---|
138 |
|
---|
139 | pkgmogrify -DVBOX_PKGNAME="$VBOX_PKGNAME" -DHARDENED_ONLY="$VBOX_DEF_HARDENED" "$PACKAGE_SPEC" "$1/vbox-ips.mog" | pkgfmt > "$PACKAGE_SPEC.1"
|
---|
140 |
|
---|
141 | pkgdepend generate -m -d "$1" "$PACKAGE_SPEC.1" | pkgfmt > "$PACKAGE_SPEC.2"
|
---|
142 |
|
---|
143 | pkgdepend resolve -m "$PACKAGE_SPEC.2"
|
---|
144 |
|
---|
145 | # Too expensive, and in this form not useful since it does not have
|
---|
146 | # the package manifests without using options -r (for repo access) and
|
---|
147 | # -c (for caching the data). Not viable since the cache would be lost
|
---|
148 | # for every build.
|
---|
149 | #pkglint "$PACKAGE_SPEC.2.res"
|
---|
150 |
|
---|
151 | pkgrepo create "$1/vbox-repo"
|
---|
152 | pkgrepo -s "$1/vbox-repo" set publisher/prefix=virtualbox
|
---|
153 |
|
---|
154 | # Create package in local file repository
|
---|
155 | pkgsend -s "$1/vbox-repo" publish -d "$1" "$PACKAGE_SPEC.2.res"
|
---|
156 |
|
---|
157 | pkgrepo -s "$1/vbox-repo" info
|
---|
158 | pkgrepo -s "$1/vbox-repo" list
|
---|
159 |
|
---|
160 | # Convert into package archive
|
---|
161 | rm -f "$1/$2"
|
---|
162 | pkgrecv -a -s "$1/vbox-repo" -d "$1/$2" -m latest "$3"
|
---|
163 | rm -rf "$1/vbox-repo"
|
---|
164 | }
|
---|
165 |
|
---|
166 | else
|
---|
167 |
|
---|
168 | package_spec_create()
|
---|
169 | {
|
---|
170 | > "$PACKAGE_SPEC"
|
---|
171 | }
|
---|
172 |
|
---|
173 | package_spec_append_info()
|
---|
174 | {
|
---|
175 | echo 'i pkginfo=vbox.pkginfo' >> "$PACKAGE_SPEC"
|
---|
176 | echo 'i checkinstall=checkinstall.sh' >> "$PACKAGE_SPEC"
|
---|
177 | echo 'i postinstall=postinstall.sh' >> "$PACKAGE_SPEC"
|
---|
178 | echo 'i preremove=preremove.sh' >> "$PACKAGE_SPEC"
|
---|
179 | echo 'i space=vbox.space' >> "$PACKAGE_SPEC"
|
---|
180 | }
|
---|
181 |
|
---|
182 | # Our package is a non-relocatable package.
|
---|
183 | #
|
---|
184 | # pkgadd will take care of "relocating" them when they are used for remote installations using
|
---|
185 | # $PKG_INSTALL_ROOT and not $BASEDIR. Seems this little subtlety led to it's own page:
|
---|
186 | # https://docs.oracle.com/cd/E19253-01/820-4042/package-2/index.html
|
---|
187 |
|
---|
188 | package_spec_append_content()
|
---|
189 | {
|
---|
190 | cd "$1"
|
---|
191 | # Exclude directories to not cause install-time conflicts with existing system directories
|
---|
192 | find . ! -type d | "$VBOX_EGREP" -v '^\./(LICENSE|prototype|makepackage\.sh|vbox\.pkginfo|postinstall\.sh|checkinstall\.sh|preremove\.sh|vbox\.space|vbox-ips.mog|virtualbox\.p5m.*)$' | LC_COLLATE=C sort | pkgproto >> "$PACKAGE_SPEC"
|
---|
193 | cd -
|
---|
194 | "$VBOX_AWK" 'NF == 3 && $1 == "s" && $2 == "none" { $3="/"$3 } { print }' "$PACKAGE_SPEC" > "$PACKAGE_SPEC.tmp"
|
---|
195 | mv -f "$PACKAGE_SPEC.tmp" "$PACKAGE_SPEC"
|
---|
196 | "$VBOX_AWK" 'NF == 6 && ($1 == "f" || $1 == "l") && ($2 == "none" || $2 == "manifest") { $3="/"$3 } { print }' "$PACKAGE_SPEC" > "$PACKAGE_SPEC.tmp"
|
---|
197 | mv -f "$PACKAGE_SPEC.tmp" "$PACKAGE_SPEC"
|
---|
198 |
|
---|
199 | cd "$1"
|
---|
200 | # Include opt/VirtualBox and subdirectories as we want uninstall to clean up directory structure.
|
---|
201 | # Include var/svc for manifest class action script does not create them.
|
---|
202 | find . -type d | "$VBOX_EGREP" 'opt/VirtualBox|var/svc/manifest/application/virtualbox' | LC_COLLATE=C sort | pkgproto >> "$PACKAGE_SPEC"
|
---|
203 | cd -
|
---|
204 | "$VBOX_AWK" 'NF == 6 && $1 == "d" && $2 == "none" { $3="/"$3 } { print }' "$PACKAGE_SPEC" > "$PACKAGE_SPEC.tmp"
|
---|
205 | mv -f "$PACKAGE_SPEC.tmp" "$PACKAGE_SPEC"
|
---|
206 | }
|
---|
207 |
|
---|
208 | package_spec_append_hardlink()
|
---|
209 | {
|
---|
210 | if [ -f "$3$4/amd64/$2" -o -f "$3$4/i386/$2" ]; then
|
---|
211 | echo "l none $4/$2=$1" >> "$PACKAGE_SPEC"
|
---|
212 | fi
|
---|
213 | }
|
---|
214 |
|
---|
215 | # Fixup filelist using awk, the parameters must be in awk syntax
|
---|
216 | # params: filename condition action
|
---|
217 | package_spec_fixup_filelist()
|
---|
218 | {
|
---|
219 | "$VBOX_AWK" 'NF == 6 && '"$1"' { '"$2"' } { print }' "$PACKAGE_SPEC" > "$PACKAGE_SPEC.tmp"
|
---|
220 | mv -f "$PACKAGE_SPEC.tmp" "$PACKAGE_SPEC"
|
---|
221 | }
|
---|
222 |
|
---|
223 | package_spec_fixup_dirlist()
|
---|
224 | {
|
---|
225 | "$VBOX_AWK" 'NF == 6 && $1 == "d" && '"$1"' { '"$2"' } { print }' "$PACKAGE_SPEC" > "$PACKAGE_SPEC.tmp"
|
---|
226 | mv -f "$PACKAGE_SPEC.tmp" "$PACKAGE_SPEC"
|
---|
227 | }
|
---|
228 |
|
---|
229 | package_spec_fixup_content()
|
---|
230 | {
|
---|
231 | # fix up file permissions (owner/group)
|
---|
232 | # don't grok for class-specific files (like sed, if any)
|
---|
233 | package_spec_fixup_filelist '$2 == "none"' '$5 = "root"; $6 = "bin"'
|
---|
234 |
|
---|
235 | # HostDriver vboxdrv
|
---|
236 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/vboxdrv.conf"' '$6 = "sys"'
|
---|
237 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/amd64/vboxdrv"' '$6 = "sys"'
|
---|
238 |
|
---|
239 | # NetFilter vboxflt
|
---|
240 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/vboxflt.conf"' '$6 = "sys"'
|
---|
241 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/amd64/vboxflt"' '$6 = "sys"'
|
---|
242 |
|
---|
243 | # NetFilter vboxbow
|
---|
244 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/vboxbow.conf"' '$6 = "sys"'
|
---|
245 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/amd64/vboxbow"' '$6 = "sys"'
|
---|
246 |
|
---|
247 | # NetAdapter vboxnet
|
---|
248 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/vboxnet.conf"' '$6 = "sys"'
|
---|
249 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/amd64/vboxnet"' '$6 = "sys"'
|
---|
250 |
|
---|
251 | # USBMonitor vboxusbmon
|
---|
252 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/vboxusbmon.conf"' '$6 = "sys"'
|
---|
253 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/amd64/vboxusbmon"' '$6 = "sys"'
|
---|
254 |
|
---|
255 | # USB Client vboxusb
|
---|
256 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/vboxusb.conf"' '$6 = "sys"'
|
---|
257 | package_spec_fixup_filelist '$3 == "/platform/i86pc/kernel/drv/amd64/vboxusb"' '$6 = "sys"'
|
---|
258 |
|
---|
259 | # Manifest class action scripts
|
---|
260 | package_spec_fixup_filelist '$3 == "/var/svc/manifest/application/virtualbox/virtualbox-webservice.xml"' '$2 = "manifest";$6 = "sys"'
|
---|
261 | if [ -z "${OPT_WITHOUT_VBoxBalloonCtrl}" ]; then
|
---|
262 | package_spec_fixup_filelist '$3 == "/var/svc/manifest/application/virtualbox/virtualbox-balloonctrl.xml"' '$2 = "manifest";$6 = "sys"'
|
---|
263 | fi
|
---|
264 | package_spec_fixup_filelist '$3 == "/var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml"' '$2 = "manifest";$6 = "sys"'
|
---|
265 |
|
---|
266 | # Use 'root' as group so as to match attributes with the previous installation and prevent a conflict. Otherwise pkgadd bails out thinking
|
---|
267 | # we're violating directory attributes of another (non existing) package
|
---|
268 | package_spec_fixup_dirlist '$3 == "/var/svc/manifest/application/virtualbox"' '$6 = "root"'
|
---|
269 |
|
---|
270 | # Hardening requires some executables to be marked setuid.
|
---|
271 | if [ -n "$HARDENED" ]; then
|
---|
272 | package_spec_fixup_filelist '( $3 == "/opt/VirtualBox/amd64/VirtualBoxVM" \
|
---|
273 | || $3 == "/opt/VirtualBox/amd64/VBoxHeadless" \
|
---|
274 | || $3 == "/opt/VirtualBox/amd64/VBoxSDL" \
|
---|
275 | || $3 == "/opt/VirtualBox/i386/VirtualBox" \
|
---|
276 | || $3 == "/opt/VirtualBox/i386/VBoxHeadless" \
|
---|
277 | || $3 == "/opt/VirtualBox/i386/VBoxSDL" )' '$4 = "4755"'
|
---|
278 | fi
|
---|
279 |
|
---|
280 | # Other executables that need setuid root (hardened or otherwise)
|
---|
281 | package_spec_fixup_filelist '( $3 == "/opt/VirtualBox/amd64/VBoxNetAdpCtl" \
|
---|
282 | || $3 == "/opt/VirtualBox/i386/VBoxNetAdpCtl" \
|
---|
283 | || $3 == "/opt/VirtualBox/amd64/VBoxNetDHCP" \
|
---|
284 | || $3 == "/opt/VirtualBox/i386/VBoxNetDHCP" \
|
---|
285 | || $3 == "/opt/VirtualBox/amd64/VBoxNetNAT" \
|
---|
286 | || $3 == "/opt/VirtualBox/i386/VBoxNetNAT" )' '$4 = "4755"'
|
---|
287 |
|
---|
288 | echo " --- start of $PACKAGE_SPEC ---"
|
---|
289 | cat "$PACKAGE_SPEC"
|
---|
290 | echo " --- end of $PACKAGE_SPEC ---"
|
---|
291 | }
|
---|
292 |
|
---|
293 | package_create()
|
---|
294 | {
|
---|
295 | # Create the package instance
|
---|
296 | pkgmk -o -f "$PACKAGE_SPEC" -r "$1"
|
---|
297 |
|
---|
298 | # Translate into package datastream
|
---|
299 | pkgtrans -s -o /var/spool/pkg "$1/$2" "$3"
|
---|
300 |
|
---|
301 | rm -rf "/var/spool/pkg/$2"
|
---|
302 | }
|
---|
303 |
|
---|
304 | fi
|
---|
305 |
|
---|
306 |
|
---|
307 | # Prepare package spec
|
---|
308 | package_spec_create
|
---|
309 |
|
---|
310 | # Metadata
|
---|
311 | package_spec_append_info "$PKG_BASE_DIR"
|
---|
312 |
|
---|
313 | # File and direcory list
|
---|
314 | package_spec_append_content "$PKG_BASE_DIR"
|
---|
315 |
|
---|
316 | # Add hardlinks for executables to launch the 32-bit or 64-bit executable
|
---|
317 | for f in VBoxManage VBoxSDL VBoxZoneAccess VBoxSVC VBoxTestOGL VirtualBox VirtualBoxVM vbox-img VBoxHeadless; do
|
---|
318 | package_spec_append_hardlink VBoxISAExec $f "$PKG_BASE_DIR" "$VBOX_INSTALLED_DIR"
|
---|
319 | done
|
---|
320 | if [ -z "${OPT_WITHOUT_VBoxBugReport}" ]; then
|
---|
321 | package_spec_append_hardlink VBoxISAExec VBoxBugReport "$PKG_BASE_DIR" "$VBOX_INSTALLED_DIR"
|
---|
322 | fi
|
---|
323 | if [ -z "${OPT_WITHOUT_VBoxBalloonCtrl}" ]; then
|
---|
324 | package_spec_append_hardlink VBoxISAExec VBoxBalloonCtrl "$PKG_BASE_DIR" "$VBOX_INSTALLED_DIR"
|
---|
325 | fi
|
---|
326 | if [ -z "${OPT_WITHOUT_VBoxAutostart}" ]; then
|
---|
327 | package_spec_append_hardlink VBoxISAExec VBoxAutostart "$PKG_BASE_DIR" "$VBOX_INSTALLED_DIR"
|
---|
328 | fi
|
---|
329 | if [ -z "${OPT_WITHOUT_vboxwebsrv}" ]; then
|
---|
330 | package_spec_append_hardlink VBoxISAExec vboxwebsrv "$PKG_BASE_DIR" "$VBOX_INSTALLED_DIR"
|
---|
331 | fi
|
---|
332 |
|
---|
333 | package_spec_fixup_content
|
---|
334 |
|
---|
335 | package_create "$PKG_BASE_DIR" "$VBOX_PKGFILE" "$VBOX_PKGNAME" "$VBOX_SVN_REV"
|
---|
336 |
|
---|
337 | echo "## Package file created successfully!"
|
---|
338 |
|
---|
339 | exit $?
|
---|