VirtualBox

source: vbox/trunk/src/VBox/Installer/darwin/VirtualBox/postflight

Last change on this file was 103063, checked in by vboxsync, 3 months ago

Installer/Python: Fixed installing bindings for Python 3 on macOS; the old syntax wasn't working on Python 3 anymore, so Python 3 probably never worked before there. bugref:10579

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1#!/bin/sh
2# $Id: postflight 103063 2024-01-25 14:12:26Z vboxsync $
3## @file
4# Post installation script.
5#
6
7#
8# Copyright (C) 2007-2023 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
29CPDIR="/bin/cp -f -R"
30INSTALL=/usr/bin/install
31
32
33#
34# Install the Python bindings
35#
36## @todo r=andy Merge this code with linux/routines.sh!
37#
38VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS
39PYTHON_INSTALLER_PATH="$VBOX_INSTALL_PATH/sdk/installer/python"
40PYTHON_BINARIES="\
41 python2.7 \
42 python2 \
43 python3.3 \
44 python3.4 \
45 python3.5 \
46 python3.6 \
47 python3.7 \
48 python3.8 \
49 python3.9 \
50 python3.10 \
51 python3.11 \
52 python3.12 \
53 python3 \
54 python"
55
56if [ -e "$PYTHON_INSTALLER_PATH/vboxapisetup.py" ]; then
57 for PYTHON_BIN in $PYTHON_BINARIES; do
58 # Install the python bindings if python is in the path
59 if [ "`\${PYTHON_BIN} -c 'print("test")' 2> /dev/null`" = "test" ]; then
60 echo 1>&2 "Python found: ${PYTHON_BIN}, installing bindings..."
61 # Pass install path via environment
62 export VBOX_INSTALL_PATH
63 # Check if python has working distutils
64 "$PYTHON_BIN" -c "from distutils.core import setup" > /dev/null 2>&1
65 if test "$?" -ne 0; then
66 echo 1>&2 "$PYTHON_BIN does not have package 'distutils', checking for 'setuptools'..."
67 # Since Python 3.12 there are no distutils anymore. See PEP632.
68 "$PYTHON_BIN" -c "from setuptools import setup" > /dev/null 2>&1
69 if test "$?" -ne 0; then
70 echo 1>&2 "$PYTHON_BIN also does not have package 'setuptools'. Skipping installation."
71 return 0
72 fi
73 # When we reach here, we have to use 'pip' in order to install our bindings (Python >= 3.12).
74 if test -x "`which pip 2>/dev/null`"; then
75 PYTHON_PIP_BIN=$(which pip)
76 else
77 echo 1>&2 "Python package manager 'pip' not found. Skipping installation."
78 fi
79 fi
80
81 if [ -n "$PYTHON_PIP_BIN" ]; then
82 # Note: We use '-v' to show verbose output of our setup.py script on error.
83 $SHELL -c "cd ${PYTHON_INSTALLER_PATH} && ${PYTHON_PIP_BIN} -v install ./vboxapi"
84 else
85 $SHELL -c "cd ${PYTHON_INSTALLER_PATH} && ${PYTHON_BIN} vboxapisetup.py install"
86 $SHELL -c "cd ${PYTHON_INSTALLER_PATH} && ${PYTHON_BIN} vboxapisetup.py clean --all"
87 fi
88 fi
89 done
90else
91 echo 1>&2 "vboxapisetup.py not found, skipping Python bindings installation."
92fi
93
94#
95# Install the vboxweb service file for launchd
96#
97VBOXWEBSRV="${VBOX_INSTALL_PATH}/org.virtualbox.vboxwebsrv.plist"
98VBOXWEBSRV_TRG="${HOME}/Library/LaunchAgents"
99if [ -e "${VBOXWEBSRV}" -a -e "${VBOXWEBSRV_TRG}" ]; then
100 echo "Installing vboxwebsrv launchd file to ${VBOXWEBSRV_TRG}"
101 if [ "x" != "x${USER}" ]; then
102 ${INSTALL} -S -o "${USER}" -m 0644 "${VBOXWEBSRV}" "${VBOXWEBSRV_TRG}/"
103 else
104 ${INSTALL} -S -m 0644 "${VBOXWEBSRV}" "${VBOXWEBSRV_TRG}/"
105 fi
106fi
107
108#
109# Install any custom files
110#
111DATAPATH="`/usr/bin/dirname "${0}"`/../../../../../.."
112if [ -d "${DATAPATH}/.custom" ]; then
113 echo 1>&2 "Copy ${DATAPATH}/.custom to ${VBOX_INSTALL_PATH}...";
114 ${CPDIR} "${DATAPATH}/.custom/" "${VBOX_INSTALL_PATH}/custom"
115fi
116
117#
118# Register our file extensions
119#
120LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
121if [ -e "${LSREGISTER}" -a "x" != "x${USER}" ]; then
122 echo "Register file extensions for \"${USER}\""
123 /usr/bin/sudo -u "${USER}" ${LSREGISTER} -f /Applications/VirtualBox.app
124 /usr/bin/sudo -u "${USER}" ${LSREGISTER} -f /Applications/VirtualBox.app/Contents/Resources/vmstarter.app
125fi
126
127# Check environment.
128if [ "${INSTALLER_TEMP}x" == "x" ]; then
129 echo "Required environment variable INSTALLER_TEMP is missing. Aborting installation."
130 exit 1;
131fi
132
133# Restore previously installed Extension Packs (if any)
134if [ -d "${INSTALLER_TEMP}/ExtensionPacks" ]; then
135 cp -r "${INSTALLER_TEMP}/ExtensionPacks" "${VBOX_INSTALL_PATH}"
136 rm -rf "${INSTALLER_TEMP}/ExtensionPacks"
137fi
138
139#
140# Correct the ownership of the directories in case there
141# was an existing installation.
142#
143chown -R root:admin /Applications/VirtualBox.app
144
145#
146# Workaround for 10.11 beta 6 in which the above chown strips the set-uid-to-root bit.
147#
148SET_UID_BINARIES="MacOS/VBoxNetAdpCtl"
149SET_UID_BINARIES="${SET_UID_BINARIES} MacOS/VBoxHeadless MacOS/VBoxNetDHCP MacOS/VBoxNetNAT Resources/VirtualBoxVM.app/Contents/MacOS/VirtualBoxVM" # WITH_HARDENING
150for bin in ${SET_UID_BINARIES}; do
151 chmod u+s "/Applications/VirtualBox.app/Contents/${bin}"
152done
153
154# Install provisioning profile if present, needed by VBoxHeadless.
155if [ -f /Applications/VirtualBox.app/Contents/embedded.provisionprofile ]; then
156 profiles -i -F /Applications/VirtualBox.app/Contents/embedded.provisionprofile
157fi
158
159exit 0;
160
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use