1 | #!/bin/sh
|
---|
2 | ## @file
|
---|
3 | #
|
---|
4 | # VirtualBox package creation script, Solaris hosts.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2007-2011 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] $(PATH_TARGET)/install packagename {$(KBUILD_TARGET_ARCH)|neutral} $(VBOX_SVN_REV) [VBIPackageName]
|
---|
22 |
|
---|
23 |
|
---|
24 | # Parse options.
|
---|
25 | HARDENED=""
|
---|
26 | while test $# -ge 1;
|
---|
27 | do
|
---|
28 | case "$1" in
|
---|
29 | --hardened)
|
---|
30 | HARDENED=1
|
---|
31 | ;;
|
---|
32 | *)
|
---|
33 | break
|
---|
34 | ;;
|
---|
35 | esac
|
---|
36 | shift
|
---|
37 | done
|
---|
38 |
|
---|
39 | if [ -z "$4" ]; then
|
---|
40 | echo "Usage: $0 installdir packagename x86|amd64 svnrev [VBIPackage]"
|
---|
41 | echo "-- packagename must not have any extension (e.g. VirtualBox-SunOS-amd64-r28899)"
|
---|
42 | exit 1
|
---|
43 | fi
|
---|
44 |
|
---|
45 | PKG_BASE_DIR=$1
|
---|
46 | VBOX_INSTALLED_DIR=$1/opt/VirtualBox
|
---|
47 | VBOX_PKGFILE=$2.pkg
|
---|
48 | VBOX_ARCHIVE=$2.tar.gz
|
---|
49 | # VBOX_PKG_ARCH is currently unused.
|
---|
50 | VBOX_PKG_ARCH=$3
|
---|
51 | VBOX_SVN_REV=$4
|
---|
52 |
|
---|
53 | VBOX_PKGNAME=SUNWvbox
|
---|
54 | VBOX_GGREP=/usr/sfw/bin/ggrep
|
---|
55 | VBOX_AWK=/usr/bin/awk
|
---|
56 | #VBOX_GTAR=/usr/sfw/bin/gtar
|
---|
57 |
|
---|
58 | # check for GNU grep we use which might not ship with all Solaris
|
---|
59 | if test ! -f "$VBOX_GGREP" && test ! -h "$VBOX_GGREP"; then
|
---|
60 | echo "## GNU grep not found in $VBOX_GGREP."
|
---|
61 | exit 1
|
---|
62 | fi
|
---|
63 |
|
---|
64 | # check for GNU tar we use which might not ship with all Solaris
|
---|
65 | #if test ! -f "$VBOX_GTAR" && test ! -h "$VBOX_GTAR"; then
|
---|
66 | # echo "## GNU tar not found in $VBOX_GTAR."
|
---|
67 | # exit 1
|
---|
68 | #fi
|
---|
69 |
|
---|
70 | # bail out on non-zero exit status
|
---|
71 | set -e
|
---|
72 |
|
---|
73 | # Fixup filelist using awk, the parameters must be in awk syntax
|
---|
74 | # params: filename condition action
|
---|
75 | filelist_fixup()
|
---|
76 | {
|
---|
77 | "$VBOX_AWK" 'NF == 6 && '"$2"' { '"$3"' } { print }' "$1" > "tmp-$1"
|
---|
78 | mv -f "tmp-$1" "$1"
|
---|
79 | }
|
---|
80 |
|
---|
81 | dirlist_fixup()
|
---|
82 | {
|
---|
83 | "$VBOX_AWK" 'NF == 6 && $1 == "d" && '"$2"' { '"$3"' } { print }' "$1" > "tmp-$1"
|
---|
84 | mv -f "tmp-$1" "$1"
|
---|
85 | }
|
---|
86 |
|
---|
87 | hardlink_fixup()
|
---|
88 | {
|
---|
89 | "$VBOX_AWK" 'NF == 3 && $1=="l" && '"$2"' { '"$3"' } { print }' "$1" > "tmp-$1"
|
---|
90 | mv -f "tmp-$1" "$1"
|
---|
91 | }
|
---|
92 |
|
---|
93 | symlink_fixup()
|
---|
94 | {
|
---|
95 | "$VBOX_AWK" 'NF == 3 && $1=="s" && '"$2"' { '"$3"' } { print }' "$1" > "tmp-$1"
|
---|
96 | mv -f "tmp-$1" "$1"
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | # Prepare file list
|
---|
101 | cd "$PKG_BASE_DIR"
|
---|
102 | echo 'i pkginfo=./vbox.pkginfo' > prototype
|
---|
103 | echo 'i checkinstall=./checkinstall.sh' >> prototype
|
---|
104 | echo 'i postinstall=./postinstall.sh' >> prototype
|
---|
105 | echo 'i preremove=./preremove.sh' >> prototype
|
---|
106 | echo 'i space=./vbox.space' >> prototype
|
---|
107 | if test -f "./vbox.copyright"; then
|
---|
108 | echo 'i copyright=./vbox.copyright' >> prototype
|
---|
109 | fi
|
---|
110 |
|
---|
111 | # Create relative hardlinks
|
---|
112 | cd "$VBOX_INSTALLED_DIR"
|
---|
113 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxManage
|
---|
114 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxSDL
|
---|
115 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxBalloonCtrl
|
---|
116 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/vboxwebsrv
|
---|
117 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/webtest
|
---|
118 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxZoneAccess
|
---|
119 | if test -f $VBOX_INSTALLED_DIR/amd64/VBoxTestOGL || test -f $VBOX_INSTALLED_DIR/i386/VBoxTestOGL; then
|
---|
120 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxTestOGL
|
---|
121 | fi
|
---|
122 |
|
---|
123 | if test -f $VBOX_INSTALLED_DIR/amd64/VirtualBox || test -f $VBOX_INSTALLED_DIR/i386/VirtualBox; then
|
---|
124 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VirtualBox
|
---|
125 | fi
|
---|
126 | if test -f $VBOX_INSTALLED_DIR/amd64/VBoxBFE || test -f $VBOX_INSTALLED_DIR/i386/VBoxBFE; then
|
---|
127 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxBFE
|
---|
128 | fi
|
---|
129 | if test -f $VBOX_INSTALLED_DIR/amd64/VBoxHeadless || test -f $VBOX_INSTALLED_DIR/i386/VBoxHeadless; then
|
---|
130 | ln -f ./VBoxISAExec $VBOX_INSTALLED_DIR/VBoxHeadless
|
---|
131 | ln -fs ./VBoxHeadless $VBOX_INSTALLED_DIR/VBoxVRDP
|
---|
132 | fi
|
---|
133 |
|
---|
134 | # Exclude directories to not cause install-time conflicts with existing system directories
|
---|
135 | cd "$PKG_BASE_DIR"
|
---|
136 | find . ! -type d | $VBOX_GGREP -v -E 'prototype|makepackage.sh|vbox.pkginfo|postinstall.sh|checkinstall.sh|preremove.sh|ReadMe.txt|vbox.space|vbox.depend|vbox.copyright|VirtualBoxKern' | pkgproto >> prototype
|
---|
137 |
|
---|
138 | # Include opt/VirtualBox and subdirectories as we want uninstall to clean up directory structure.
|
---|
139 | # Include var/svc for manifest class action script does not create them.
|
---|
140 | find . -type d | $VBOX_GGREP -E 'opt/VirtualBox|var/svc/manifest/application/virtualbox' | pkgproto >> prototype
|
---|
141 |
|
---|
142 | # fix up file permissions (owner/group)
|
---|
143 | # don't grok for class-specific files (like sed, if any)
|
---|
144 | filelist_fixup prototype '$2 == "none"' '$5 = "root"; $6 = "bin"'
|
---|
145 |
|
---|
146 | # don't include autoresponse and LICENSE from the base folder into / of
|
---|
147 | # the package, it goes into .tar.gz and another one already exists
|
---|
148 | # in /opt/VirtualBox
|
---|
149 | sed '/f none autoresponse/d' prototype > prototype2
|
---|
150 | mv -f prototype2 prototype
|
---|
151 | sed '/f none LICENSE/d' prototype > prototype2
|
---|
152 | mv -f prototype2 prototype
|
---|
153 |
|
---|
154 | # HostDriver vboxdrv
|
---|
155 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/vboxdrv"' '$6 = "sys"'
|
---|
156 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/amd64/vboxdrv"' '$6 = "sys"'
|
---|
157 |
|
---|
158 | # NetFilter vboxflt
|
---|
159 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/vboxflt"' '$6 = "sys"'
|
---|
160 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/amd64/vboxflt"' '$6 = "sys"'
|
---|
161 |
|
---|
162 | # NetFilter vboxbow
|
---|
163 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/vboxbow"' '$6 = "sys"'
|
---|
164 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/amd64/vboxbow"' '$6 = "sys"'
|
---|
165 |
|
---|
166 | # NetAdapter vboxnet
|
---|
167 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/vboxnet"' '$6 = "sys"'
|
---|
168 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/amd64/vboxnet"' '$6 = "sys"'
|
---|
169 |
|
---|
170 | # USBMonitor vboxusbmon
|
---|
171 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/vboxusbmon"' '$6 = "sys"'
|
---|
172 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/amd64/vboxusbmon"' '$6 = "sys"'
|
---|
173 |
|
---|
174 | # USB Client vboxusb
|
---|
175 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/vboxusb"' '$6 = "sys"'
|
---|
176 | filelist_fixup prototype '$3 == "platform/i86pc/kernel/drv/amd64/vboxusb"' '$6 = "sys"'
|
---|
177 |
|
---|
178 | # Manifest class action scripts
|
---|
179 | filelist_fixup prototype '$3 == "var/svc/manifest/application/virtualbox/virtualbox-webservice.xml"' '$2 = "manifest";$6 = "sys"'
|
---|
180 | filelist_fixup prototype '$3 == "var/svc/manifest/application/virtualbox/virtualbox-balloonctrl.xml"' '$2 = "manifest";$6 = "sys"'
|
---|
181 | filelist_fixup prototype '$3 == "var/svc/manifest/application/virtualbox/virtualbox-zoneaccess.xml"' '$2 = "manifest";$6 = "sys"'
|
---|
182 |
|
---|
183 | # Use 'root' as group so as to match attributes with the previous installation and prevent a conflict. Otherwise pkgadd bails out thinking
|
---|
184 | # we're violating directory attributes of another (non existing) package
|
---|
185 | dirlist_fixup prototype '$3 == "var/svc/manifest/application/virtualbox"' '$6 = "root"'
|
---|
186 |
|
---|
187 | # hardening requires some executables to be marked setuid.
|
---|
188 | if test -n "$HARDENED"; then
|
---|
189 | $VBOX_AWK 'NF == 6 \
|
---|
190 | && ( $3 == "opt/VirtualBox/amd64/VirtualBox" \
|
---|
191 | || $3 == "opt/VirtualBox/amd64/VirtualBox3" \
|
---|
192 | || $3 == "opt/VirtualBox/amd64/VBoxHeadless" \
|
---|
193 | || $3 == "opt/VirtualBox/amd64/VBoxSDL" \
|
---|
194 | || $3 == "opt/VirtualBox/amd64/VBoxBFE" \
|
---|
195 | || $3 == "opt/VirtualBox/i386/VirtualBox" \
|
---|
196 | || $3 == "opt/VirtualBox/i386/VirtualBox3" \
|
---|
197 | || $3 == "opt/VirtualBox/i386/VBoxHeadless" \
|
---|
198 | || $3 == "opt/VirtualBox/i386/VBoxSDL" \
|
---|
199 | || $3 == "opt/VirtualBox/i386/VBoxBFE" \
|
---|
200 | ) \
|
---|
201 | { $4 = "4755" } { print }' prototype > prototype2
|
---|
202 | mv -f prototype2 prototype
|
---|
203 | fi
|
---|
204 |
|
---|
205 | # Other executables that need setuid root (hardened or otherwise)
|
---|
206 | $VBOX_AWK 'NF == 6 \
|
---|
207 | && ( $3 == "opt/VirtualBox/amd64/VBoxNetAdpCtl" \
|
---|
208 | || $3 == "opt/VirtualBox/i386/VBoxNetAdpCtl" \
|
---|
209 | || $3 == "opt/VirtualBox/amd64/VBoxNetDHCP" \
|
---|
210 | || $3 == "opt/VirtualBox/i386/VBoxNetDHCP" \
|
---|
211 | ) \
|
---|
212 | { $4 = "4755" } { print }' prototype > prototype2
|
---|
213 | mv -f prototype2 prototype
|
---|
214 |
|
---|
215 | # Our package is a non-relocatable package. pkgadd will take care of "relocating" them when they are used for
|
---|
216 | # remote installations using $PKG_INSTALL_ROOT and not $BASEDIR. Seems this little subtlety led to it's own page:
|
---|
217 | # http://docs.sun.com/app/docs/doc/820-4042/package-2?a=view
|
---|
218 | filelist_fixup prototype '$2 == "none"' '$3="/"$3'
|
---|
219 | filelist_fixup prototype '$2 == "manifest"' '$3="/"$3'
|
---|
220 | symlink_fixup prototype '$2 == "none"' '$3="/"$3'
|
---|
221 | hardlink_fixup prototype '$2 == "none"' '$3="/"$3'
|
---|
222 |
|
---|
223 | echo " --- start of prototype ---"
|
---|
224 | cat prototype
|
---|
225 | echo " --- end of prototype --- "
|
---|
226 |
|
---|
227 | # Explicitly set timestamp to shutup warning
|
---|
228 | VBOXPKG_TIMESTAMP=vbox`date '+%Y%m%d%H%M%S'`_r$VBOX_SVN_REV
|
---|
229 |
|
---|
230 | # Create the package instance
|
---|
231 | pkgmk -p $VBOXPKG_TIMESTAMP -o -r .
|
---|
232 |
|
---|
233 | # Translate into package datastream
|
---|
234 | pkgtrans -s -o /var/spool/pkg "`pwd`/$VBOX_PKGFILE" "$VBOX_PKGNAME"
|
---|
235 |
|
---|
236 | # $5 if exist would contain the path to the VBI package to include in the .tar.gz
|
---|
237 | #if [ -f LICENSE ]; then
|
---|
238 | # VBOX_LICENSEFILE=LICENSE
|
---|
239 | #fi
|
---|
240 | #if test -f "$5"; then
|
---|
241 | # $VBOX_GTAR zcvf "$VBOX_ARCHIVE" $VBOX_LICENSEFILE "$VBOX_PKGFILE" "$5" autoresponse ReadMe.txt
|
---|
242 | #else
|
---|
243 | # $VBOX_GTAR zcvf "$VBOX_ARCHIVE" $VBOX_LICENSEFILE "$VBOX_PKGFILE" autoresponse ReadMe.txt
|
---|
244 | #fi
|
---|
245 |
|
---|
246 | echo "## Package file created successfully!"
|
---|
247 | rm -rf "/var/spool/pkg/$VBOX_PKGNAME"
|
---|
248 |
|
---|
249 | exit $?
|
---|
250 |
|
---|