#!/bin/bash
### BEGIN BOOT SCRIPT INFO
#Long-Name: 86Box
### END BOOT SCRIPT INFO
### BEGIN BOOT SCRIPT INSTALLATION DEFAULTS
#Launch-Mode: gui-only
### END BOOT SCRIPT INSTALLATION DEFAULTS
#
#Files/directories required by this script:
#
#86box.cfg	86Box configuration file
#roms		ROM directory (normally a symlink to pc/SUPPORT/86box_roms
#
#Optional files supported by this script:
#86BOX_OPTS	Scriptlet to change the 86Box version by setting @_86BOX_VERSION#

. bootscriptfunctions.sh

_86BOX_VERSION="$OSM_EMULATOR_VERSION"

if [ -z "$_86BOX_VERSION" ]
then
	_86BOX_VERSION="$CONF_DEFAULT_86BOX_VERSION"
fi

#if there is a known-good NVRAM image and time synchronization is disabled,
#revert the NVRAM (this allows starting with a fixed RTC date to prevent
#timebomb activation in beta OSes)
if [ -d nvr.base ] && grep -q 'time_sync = disabled' 86box.cfg
then
	rm -rf nvr
	cp -R nvr.base nvr
fi

#remove the UUID to stop 86Box from asking whether the VM has been moved/copied
#TODO?: handle this better?
sed -Ei 's/^uuid = [0-9a-z-]+$//' 86box.cfg

exec "86Box-${_86BOX_VERSION}" -P . -R ./roms -V "`get_long_name_with_version | tr \\" \\'`"
