#!/bin/sh

if [ "$(id -u)" -ne 0 ]; then
	echo 'live-installer must be run with sudo.' >&2
	exit 1
fi

# Inject eject message within plymouth theme (LMDE only, Mint's live system already asks to remove the media)
if [ -e /usr/share/doc/debian-system-adjustments/copyright ]; then
	msg="SubTitle=Remove the installation media and press ENTER to continue..."
	theme_file=/usr/share/plymouth/themes/mint-logo/mint-logo.plymouth
	sed -i -e "/${msg}/d" ${theme_file}
	sed -i -e "/\[reboot\]/a ${msg}" ${theme_file}
	sed -i -e "/\[shutdown\]/a ${msg}" ${theme_file}
fi

optimize='OO'; case "$*" in *--debug*) unset optimize; esac

# Slideshow is broken in virtualbox without this.
export WEBKIT_DISABLE_COMPOSITING_MODE=1

# Keep a log of the installation, it is copied to the installed system
# (-u: unbuffered, so the output stays in order with the commands it runs)
python3 -u -tt${optimize} //usr/lib/live-installer/main.py "$@" 2>&1 | tee -a /var/log/live-installer.log
