#!/bin/bash

mkdir /etc/vbox
echo "default_policy = allow" > /etc/vbox/autostart.config

echo "0" > /etc/vbox/mib.start
chown mib:mib /etc/vbox/mib.start 

echo "VBOXAUTOSTART_DB=/etc/vbox" >> /etc/default/virtualbox
echo "VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.config" >> /etc/default/virtualbox 

su - mib -C "VBoxManage setproperty autostartdbpath /etc/vbox"

# Bob is allowed to start virtual machines but starting them
# will be delayed for 10 seconds
#mib = {
#    allow = true
#    startup_delay = 3
#}

mkdir -p /usr/lib/vbox-autostart-mib
cd /usr/lib/vbox-autostart-mib
wget https://alexmib.ru/z/linux-setup/vboxautostart/custom/vbox-autostart-mib.sh
chmod +x ./vbox-autostart-mib.sh

cd -

cd /usr/lib/systemd/system/
wget https://alexmib.ru/z/linux-setup/vboxautostart/custom/vbox-autostart-mib.service

systemctl daemon-reload
systemctl list-unit-files | egrep 'vbox-autostart-mib'

systemctl enable vbox-autostart-mib
systemctl start vbox-autostart-mib



