[42379] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 | #
|
---|
[98103] | 4 | # Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[42379] | 5 | #
|
---|
[96407] | 6 | # This file is part of VirtualBox base platform packages, as
|
---|
| 7 | # available from https://www.virtualbox.org.
|
---|
[42379] | 8 | #
|
---|
[96407] | 9 | # This program is free software; you can redistribute it and/or
|
---|
| 10 | # modify it under the terms of the GNU General Public License
|
---|
| 11 | # as published by the Free Software Foundation, in version 3 of the
|
---|
| 12 | # License.
|
---|
| 13 | #
|
---|
| 14 | # This program is distributed in the hope that it will be useful, but
|
---|
| 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 17 | # General Public License for more details.
|
---|
| 18 | #
|
---|
| 19 | # You should have received a copy of the GNU General Public License
|
---|
| 20 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 21 | #
|
---|
| 22 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
| 23 | #
|
---|
[42379] | 24 |
|
---|
| 25 | #
|
---|
| 26 | # Wrapper for the per user autostart daemon. Gets a list of all users
|
---|
| 27 | # and starts the VMs.
|
---|
| 28 | #
|
---|
| 29 |
|
---|
[43656] | 30 | function vboxStartStopAllUserVms()
|
---|
[42379] | 31 | {
|
---|
| 32 | # Go through the list and filter out all users without a shell and a
|
---|
| 33 | # non existing home.
|
---|
| 34 | for user in `dscl . -list /Users`
|
---|
| 35 | do
|
---|
[88527] | 36 | HOMEDIR=`dscl . -read /Users/"${user}" NFSHomeDirectory | sed 's/NFSHomeDirectory: //g'`
|
---|
| 37 | USERSHELL=`dscl . -read /Users/"${user}" UserShell | sed 's/UserShell: //g'`
|
---|
[42379] | 38 |
|
---|
| 39 | # Check for known home directories and shells for daemons
|
---|
[42384] | 40 | if [[ "${HOMEDIR}" == "/var/empty" || "${HOMEDIR}" == "/dev/null" || "${HOMEDIR}" == "/var/root"
|
---|
[42379] | 41 | || "${USERSHELL}" == "/usr/bin/false" || "${USERSHELL}" == "/dev/null" || "${USERSHELL}" == "/usr/sbin/uucico" ]]
|
---|
| 42 | then
|
---|
| 43 | continue
|
---|
| 44 | fi
|
---|
| 45 |
|
---|
[43656] | 46 | case "${1}" in
|
---|
| 47 | start)
|
---|
| 48 | # Start the daemon
|
---|
[88527] | 49 | su "${user}" -c "/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart --quiet --start --background --config ${CONFIG}"
|
---|
[43656] | 50 | ;;
|
---|
| 51 | stop)
|
---|
[88527] | 52 | # Stop the daemon
|
---|
| 53 | su "${user}" -c "/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart --quiet --stop --config ${CONFIG}"
|
---|
[43656] | 54 | ;;
|
---|
| 55 | *)
|
---|
| 56 | echo "Usage: start|stop"
|
---|
| 57 | exit 1
|
---|
| 58 | esac
|
---|
[42379] | 59 | done
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[43656] | 62 | function vboxStopAllUserVms()
|
---|
| 63 | {
|
---|
| 64 | vboxStartStopAllUserVms "stop"
|
---|
| 65 | }
|
---|
[42379] | 66 |
|
---|
[43656] | 67 | CONFIG=${1}
|
---|
| 68 | vboxStartStopAllUserVms "start"
|
---|
| 69 | trap vboxStopAllUserVms HUP KILL TERM
|
---|
| 70 |
|
---|
| 71 |
|
---|