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