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