56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync#!/bin/sh
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync#
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# Copyright (C) 2012 Oracle Corporation
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync#
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# available from http://www.virtualbox.org. This file is free software;
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# you can redistribute it and/or modify it under the terms of the GNU
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# General Public License (GPL) as published by the Free Software
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync#
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync#
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# Wrapper for the per user autostart daemon. Gets a list of all users
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync# and starts the VMs.
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync#
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsyncfunction vboxStartStopAllUserVms()
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync{
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync # Go through the list and filter out all users without a shell and a
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync # non existing home.
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync for user in `dscl . -list /Users`
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync do
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync HOMEDIR=`dscl . -read /Users/${user} | grep NFSHomeDirectory | sed 's/NFSHomeDirectory: //g'`
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync USERSHELL=`dscl . -read /Users/${user} | grep UserShell | sed 's/UserShell: //g'`
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync # Check for known home directories and shells for daemons
e366e4992f5d81a0b93412e10d2ef9dc06f930edvboxsync if [[ "${HOMEDIR}" == "/var/empty" || "${HOMEDIR}" == "/dev/null" || "${HOMEDIR}" == "/var/root"
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync || "${USERSHELL}" == "/usr/bin/false" || "${USERSHELL}" == "/dev/null" || "${USERSHELL}" == "/usr/sbin/uucico" ]]
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync then
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync continue
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync fi
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync case "${1}" in
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync start)
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync # Start the daemon
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync su ${user} -c "/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart --quiet --start --background --config ${CONFIG}"
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync ;;
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync stop)
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync # Start the daemon
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync su ${user} -c "/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart --quiet --stop --config ${CONFIG}"
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync ;;
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync *)
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync echo "Usage: start|stop"
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync exit 1
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync esac
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync done
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync}
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsyncfunction vboxStopAllUserVms()
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync{
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync vboxStartStopAllUserVms "stop"
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync}
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsyncCONFIG=${1}
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsyncvboxStartStopAllUserVms "start"
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsynctrap vboxStopAllUserVms HUP KILL TERM
0073ab680739b243ea5b24de5e7d016ee87bab94vboxsync
56a353f79df8b3f9ae8d5ff5adc1d373524e3ad4vboxsync