VirtualBox

source: vbox/trunk/src/VBox/Installer/solaris/makepackage.sh@ 87035

Last change on this file since 87035 was 87035, checked in by vboxsync, 4 years ago

Installer/solaris: Big cleanup of SysV packging, and first cut (so far the result will not be usable, permissions and so on need fixing) of IPS packaging. bugref:5999

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette