#!/bin/sh
#
# Copyright 2006-2009 by Purdue Research Foundation, West Lafayette, IN 47906.
# All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License, version 2.1 as published by the Free Software Foundation.

# Someday this should support customization by site admin
# But its awkward to have to change links. Punting
# until I have a site requirement needing this.
#
# Someday it should be: invoke-icewm -t config-template [--captive | -c]
# right now its just: invoke [captive]
#

CONFIGDIR=/usr/lib/hubzero/icewm/config

if [ "$1" != "captive" ]
then
	[[ -d .icewm ]] || {
  		mkdir .icewm
	}

	[[ -e .icewm/keys ]] || {
  		ln -s ${CONFIGDIR}/default/keys .icewm/keys
	}

	[[ -e .icewm/menu ]] || {
  		ln -s ${CONFIGDIR}/default/menu .icewm/menu
	}

	[[ -e .icewm/toolbar ]] || {
  		ln -s ${CONFIGDIR}/default/toolbar .icewm/toolbar
	}

	[[ -e .icewm/preferences ]] || {
  		ln -s ${CONFIGDIR}/default/preferences .icewm/preferences
	}

	[[ -e .icewm/theme ]] || {
  		ln -s ${CONFIGDIR}/default/theme .icewm/theme
	}

	[[ -e /usr/bin/icewm-session ]] && exec /usr/bin/icewm-session

	# If no window manager just sleep "forever."

	exec sleep 1000000000
else

	/usr/bin/xsetroot -solid "#3A6EA5"

	ICEWM_PRIVCFG=${CONFIGDIR}/captive
	export ICEWM_PRIVCFG

	cd ${HOME}

	[[ -e /usr/bin/icewm ]] && exec /usr/bin/icewm
fi
