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
RevLine 
[31655]1#!/bin/sh
[54676]2# $Id: postflight 103063 2024-01-25 14:12:26Z vboxsync $
3## @file
4# Post installation script.
5#
[31655]6
7#
[98103]8# Copyright (C) 2007-2023 Oracle and/or its affiliates.
[31655]9#
[96407]10# This file is part of VirtualBox base platform packages, as
11# available from https://www.virtualbox.org.
[31655]12#
[96407]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#
[31655]28
[85100]29CPDIR="/bin/cp -f -R"
30INSTALL=/usr/bin/install
[31940]31
[31655]32
33#
34# Install the Python bindings
35#
[103028]36## @todo r=andy Merge this code with linux/routines.sh!
37#
[31655]38VBOX_INSTALL_PATH=/Applications/VirtualBox.app/Contents/MacOS
[103028]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
[69396]58 # Install the python bindings if python is in the path
[103063]59 if [ "`\${PYTHON_BIN} -c 'print("test")' 2> /dev/null`" = "test" ]; then
[103028]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
[103062]66 echo 1>&2 "$PYTHON_BIN does not have package 'distutils', checking for 'setuptools'..."
[103028]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
[103062]70 echo 1>&2 "$PYTHON_BIN also does not have package 'setuptools'. Skipping installation."
[103028]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
[69396]88 fi
[31655]89 done
[103062]90else
91 echo 1>&2 "vboxapisetup.py not found, skipping Python bindings installation."
[31655]92fi
93
94#
[31940]95# Install the vboxweb service file for launchd
96#
97VBOXWEBSRV="${VBOX_INSTALL_PATH}/org.virtualbox.vboxwebsrv.plist"
98VBOXWEBSRV_TRG="${HOME}/Library/LaunchAgents"
[85100]99if [ -e "${VBOXWEBSRV}" -a -e "${VBOXWEBSRV_TRG}" ]; then
[34275]100 echo "Installing vboxwebsrv launchd file to ${VBOXWEBSRV_TRG}"
[85100]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
[31940]106fi
107
108#
[31655]109# Install any custom files
110#
111DATAPATH="`/usr/bin/dirname "${0}"`/../../../../../.."
112if [ -d "${DATAPATH}/.custom" ]; then
[34275]113 echo 1>&2 "Copy ${DATAPATH}/.custom to ${VBOX_INSTALL_PATH}...";
114 ${CPDIR} "${DATAPATH}/.custom/" "${VBOX_INSTALL_PATH}/custom"
[31655]115fi
116
[34275]117#
118# Register our file extensions
119#
120LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
[85100]121if [ -e "${LSREGISTER}" -a "x" != "x${USER}" ]; then
[38522]122 echo "Register file extensions for \"${USER}\""
[34275]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
[47366]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
[47362]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
[47366]139#
[57328]140# Correct the ownership of the directories in case there
141# was an existing installation.
[57231]142#
[57328]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#
[83054]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
[57231]150for bin in ${SET_UID_BINARIES}; do
[83054]151 chmod u+s "/Applications/VirtualBox.app/Contents/${bin}"
[57231]152done
153
[89013]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
[31655]159exit 0;
[54676]160
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use