aboutsummaryrefslogtreecommitdiff
path: root/system/virtualbox/virtualbox.SlackBuild
blob: c2438c82d2682cd5624db17568c65238471dd340 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/sh

# Slackware build script for virtualbox-ose

# Copyright 2008-2020 Heinz Wiesinger, Amsterdam, The Netherlands
# Copyright 2008 Mauro Giachero <mauro.giachero@gmail.com>
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

PRGNAM=virtualbox
SRCNAM=VirtualBox
VERSION=${VERSION:-6.1.8}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# kmk doesn't support MAKEFLAGS, so we use JOBS here
JOBS=${JOBS:-3}

# Define Variable Names
gui=""

# Check for vboxusers group here
if ! grep ^vboxusers: /etc/group 2>&1 > /dev/null; then
  echo "  You must have a vboxusers group to run this script."
  echo "    # groupadd -g 215 vboxusers"
  exit 1
fi

# Enable Hardening - Defaulting to yes as requested by upstream
if [ "${HARDENING:-yes}" = "yes" ]; then
  harden="--enable-hardening"
else
  harden="--disable-hardening"
fi

# Support for the Qt & SDL frontends
if [ "${HEADLESS:-no}" = "no" ]; then
  guiapp="VirtualBox VirtualBoxVM VBoxSDL"
  suidgui="VirtualBoxVM VBoxSDL"
else
  gui+=" --build-headless"
  guiapp=""
  suidgui=""
fi

# Enable building of java bindings
if [ "${JAVA:-no}" = "no" ]; then
  java="--disable-java"
else
  java=""
fi

if [ "${WEBSERVICE:-no}" = "no" ]; then
    web_service=""
    vboxwebsrv=""
else
    web_service="--enable-webservice"
    vboxwebsrv="vboxwebsrv"
    if ! grep ^vboxweb: /etc/passwd 2>&1 > /dev/null; then
      echo "  You must have a vboxweb user to run this script."
      echo "    # useradd -u 240 -g 215 -d /var/lib/vboxweb vboxweb"
      exit 1
    fi
fi

if [ "${SOFTWARE_VIRTUALIZATION:-no}" = "no" -a "$ARCH" = "x86_64" ]; then
    sw_virt="--disable-vmmraw"
else
    sw_virt=""
fi

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
  LIBDIRSUFFIX=""
  BUILDDIR="x86"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
  BUILDDIR="x86"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
  BUILDDIR="amd64"
fi

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM-${VERSION}
tar xvf $CWD/$SRCNAM-${VERSION}.tar.bz2
cd $SRCNAM-${VERSION}
chown -R root:root .
find -L . \
 \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
  -o -perm 511 \) -exec chmod 755 {} \; -o \
 \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
  -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;

GROUP="vboxusers"
MODE="755"

# We don't want an init-script building kernel modules.
# Use virtualbox-kernel.SlackBuild for this.
patch -d src/VBox/Installer/linux -i $CWD/vboxdrv.sh-setup.diff

# Fix wrong path to rdesktop-vrdp-keymaps
patch -p1 -i $CWD/006-rdesktop-vrdp-keymap-path.patch

# Remove gcc version check
sed -i 's/^check_gcc$/#check_gcc/' ./configure

# Use our CFLAGS
sed -i "s|CXX_FLAGS=\"\"|CXX_FLAGS=\"$SLKCFLAGS -std=c++11\"|" ./configure

./configure \
  --disable-kmods \
  --enable-vde \
  --enable-vnc \
  --with-makeself=/usr/bin/echo \
  $web_service \
  $harden \
  $gui \
  $sw_virt \
  $java

. ./env.sh

cp $CWD/LocalConfig.kmk .
sed -i "s|LIBDIR|lib$LIBDIRSUFFIX|" ./LocalConfig.kmk
sed -i "s|CXXFLAGS|$SLKCFLAGS -std=c++11|" ./LocalConfig.kmk

kmk -j ${JOBS} LOCALCFG=./LocalConfig.kmk

mkdir -p $PKG/usr/{lib$LIBDIRSUFFIX,share,include}/virtualbox \
  $PKG/usr/{bin,src} \
  $PKG/usr/share/{pixmaps,mime/packages} \
  $PKG/etc/{default,rc.d,vbox}

for i in vboxdrv.sh vboxballoonctrl-service.sh vboxautostart-service.sh; do
  SCRIPT=$(echo $i | cut -d "." -f 1)
  cp -f src/VBox/Installer/linux/$i $PKG/etc/rc.d/rc.$SCRIPT.new
  sed -i "s/%PACKAGE%/virtualbox/g" $PKG/etc/rc.d/rc.$SCRIPT.new
  sed -i "s/%NOLSB%/yes/" $PKG/etc/rc.d/rc.$SCRIPT.new
  sed -i "s/%DEBIAN%/no/" $PKG/etc/rc.d/rc.$SCRIPT.new
  sed -i "s/%GROUP%/vboxusers/" $PKG/etc/rc.d/rc.$SCRIPT.new
  sed -i "s/\[ -z \"\$DEBIAN\"/#\[ -z \"\$DEBIAN\"/" $PKG/etc/rc.d/rc.$SCRIPT.new
done

cp -f $CWD/vbox.cfg $PKG/etc/vbox/vbox.cfg.new
sed -i "s|LIBDIR|lib$LIBDIRSUFFIX|" $PKG/etc/vbox/vbox.cfg.new
cp -f $CWD/virtualbox.default $PKG/etc/default/virtualbox.new

cd out/linux.$BUILDDIR/release/bin/
  rm -f vboxdrv.ko
  mv src $PKG/usr/src/virtualbox-kernel-$VERSION

  if [ "${HEADLESS:-no}" = "no" ]; then
    mkdir -p $PKG/usr/share/applications
    mv virtualbox.desktop $PKG/usr/share/applications/
    sed -i "s|/opt/VirtualBox|/usr/share/virtualbox|" \
      $PKG/usr/share/applications/virtualbox.desktop
    mv nls* *.tar.bz2 $PKG/usr/share/virtualbox/
  fi
  mv VBox.png $PKG/usr/share/pixmaps/

  cd icons
    for i in *; do
      install -d $PKG/usr/share/icons/hicolor/$i/mimetypes
      mv $i/* $PKG/usr/share/icons/hicolor/$i/mimetypes
    done
  cd -
  rm -rf icons

  mv virtualbox.xml $PKG/usr/share/mime/packages

  export VBOX_INSTALL_PATH=/usr/lib$LIBDIRSUFFIX/virtualbox
  cd sdk/installer
    python ./vboxapisetup.py install --prefix "/usr" --root $PKG
  cd -
  rm -rf sdk/installer

  mv sdk $PKG/usr/share/virtualbox/
  install -m $MODE -g $GROUP VBoxSysInfo.sh $PKG/usr/share/virtualbox/
  install -m $MODE -g $GROUP VBoxCreateUSBNode.sh $PKG/usr/share/virtualbox/
  install -m $MODE -g $GROUP VBoxTunctl $PKG/usr/bin/
  rm -f VBoxSysInfo.sh VBoxCreateUSBNode.sh VBoxTunctl
  mv * $PKG/usr/lib$LIBDIRSUFFIX/virtualbox/
  chown -R root:$GROUP $PKG/usr/lib$LIBDIRSUFFIX/virtualbox/
  chmod -R $MODE $PKG/usr/lib$LIBDIRSUFFIX/virtualbox/
  mv $PKG/usr/lib$LIBDIRSUFFIX/virtualbox/VBox.sh $PKG/usr/lib$LIBDIRSUFFIX/virtualbox/VBox
cd $TMP/$SRCNAM-${VERSION}

for i in VBoxManage VBoxHeadless VBoxVRDP VBoxBalloonCtrl VBoxBugReport \
  VBoxAutostart $guiapp $vboxwebsrv; do
  ln -s /usr/lib$LIBDIRSUFFIX/virtualbox/VBox $PKG/usr/bin/$i
done

if [ "${HEADLESS:-no}" = "no" ]; then
  for i in virtualbox vboxsdl; do
    ln -s /usr/lib$LIBDIRSUFFIX/virtualbox/VBox $PKG/usr/bin/$i
  done
fi

ln -s /usr/lib$LIBDIRSUFFIX/virtualbox/vbox-img $PKG/usr/bin/
ln -s /usr/lib$LIBDIRSUFFIX/virtualbox/vboximg-mount $PKG/usr/bin/

if [ "$vboxwebsrv" = "vboxwebsrv" ]; then
  mkdir -p $PKG/var/{lib,log}/vboxweb
  chown vboxweb:vboxusers $PKG/var/{lib,log}/vboxweb
  cp -f src/VBox/Installer/linux/vboxweb-service.sh $PKG/etc/rc.d/rc.vboxweb-service.new
  sed -i "s/%PACKAGE%/virtualbox/g" $PKG/etc/rc.d/rc.vboxweb-service.new
  sed -i "s/%NOLSB%/yes/" $PKG/etc/rc.d/rc.vboxweb-service.new
  sed -i "s/%DEBIAN%/no/" $PKG/etc/rc.d/rc.vboxweb-service.new
  sed -i "s/\[ -z \"\$DEBIAN\"/#\[ -z \"\$DEBIAN\"/" $PKG/etc/rc.d/rc.vboxweb-service.new
fi

if [ "$harden" = "--enable-hardening" ]; then
  for i in VBoxHeadless $suidgui VBoxNetDHCP VBoxNetAdpCtl VBoxNetNAT; do
    chmod 4711 $PKG/usr/lib$LIBDIRSUFFIX/virtualbox/$i
  done
fi

# install headers. Needed by some third party tools
cp -rf include/* $PKG/usr/include/virtualbox/
rm -f $PKG/usr/include/virtualbox/Makefile.kmk
find $PKG/usr/include/virtualbox -name "Makefile.kup" -print0 | xargs -0 rm -f

cp -f $CWD/VBoxGuestAdditions_$VERSION.iso \
  $PKG/usr/share/virtualbox/VBoxGuestAdditions.iso

cp -f $CWD/UserManual.pdf \
  $PKG/usr/share/virtualbox/UserManual.pdf

cp -f $CWD/SDKRef.pdf \
  $PKG/usr/share/virtualbox/SDKRef.pdf

# install profile.d scripts for 3rd party apps
mkdir -p $PKG/etc/profile.d/
cat << EOF > $PKG/etc/profile.d/vbox.csh
#!/bin/csh
setenv VBOX_PROGRAM_PATH /usr/lib${LIBDIRSUFFIX}/virtualbox/
setenv VBOX_SDK_PATH /usr/share/virtualbox/sdk/
EOF
cat << EOF > $PKG/etc/profile.d/vbox.sh
#!/bin/sh
export VBOX_PROGRAM_PATH=/usr/lib${LIBDIRSUFFIX}/virtualbox/
export VBOX_SDK_PATH=/usr/share/virtualbox/sdk/
EOF
chmod 0755 $PKG/etc/profile.d/*

# setup udev rules for vboxdrv and USB device support
mkdir -p $PKG/lib/udev/rules.d
install -m 644 $CWD/10-virtualbox.rules $PKG/lib/udev/rules.d/

find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
  | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -f COPYING COPYING.CDDL $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/README.SLACKWARE > $PKG/usr/doc/$PRGNAM-$VERSION/README.SLACKWARE
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

if [ "$vboxwebsrv" = "vboxwebsrv" ]; then
  echo "preserve_perms etc/rc.d/rc.vboxweb-service.new" >> $PKG/install/doinst.sh
fi

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}