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