#!/bin/sh

# TODO: only localhost or so in the future
xhost +

# whether auto-install mode is requested
if grep -q install /proc/cmdline ; then
	sudo /home/archivista/install.sh -auto
else
	[ -f /etc/av-button.conf ] && . /etc/av-button.conf
	if [ "$av_button"  = 1 ]; then
		ps -C av-xevie-sb >/dev/null || sudo /usr/bin/av-xevie-sb \
		     --script /home/cvs/archivista/jobs/sane-button.pl &
	fi

	if [ -f /etc/vnc.conf ]; then
		unset autostart passwd
		. /etc/vnc.conf
		[ "$autostart" = 1 -a "$passwd" ] &&
			# if changed, ~/vnc-enable.sh needs an update as well
			x11vnc -forever -passwd "$passwd" -skip_lockkeys &
	fi

	/home/archivista/kbd.sh
	sudo /home/archivista/network.sh

	# remove install entry for installed versions or copy the
	# backup vanila version for published ISOs
	[ -e ~/.fluxbox/menu.orig ] || cp ~/.fluxbox/menu{,.orig}
	if ! grep -q /mnt/live /proc/mounts; then # not livecd ?
		sed '/install\.sh/d' ~/.fluxbox/menu.orig > ~/.fluxbox/menu
	else
		sed '/publish\.sh/d' ~/.fluxbox/menu.orig > ~/.fluxbox/menu
	fi

	firefox http://localhost/perl/avclient/index.pl &
fi
