#!/bin/sh
#
# $Id: update_wms,v 1.2 2003/01/21 16:06:05 ldv Exp $
# Copyright (C) 2002,2003  Dmitry V. Levin <ldv@altlinux.org>
#
# Updates window manager session lists.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

runwmlist="`/usr/X11R6/bin/runwm --list`" || exit 1

# KDM
if [ -s /etc/X11/kdm/kdmrc ]; then
	subst "s|^\\(SessionTypes\\)=.*|\\1=$(echo -n $runwmlist |/usr/bin/tr ' ' ,)|" \
		/etc/X11/kdm/kdmrc
fi

# WDM
if [ -s /etc/X11/wdm/wdm-config ]; then
	subst "s|^\\(DisplayManager\\*wdmWm\\):.*|\\1:$(echo -n $runwmlist |/usr/bin/tr ' ' :)|" \
		/etc/X11/wdm/wdm-config
fi

# GDM
if [ -d /etc/X11/gdm/Sessions ]; then
	rm -f /etc/X11/gdm/Sessions/*
	for n in $runwmlist; do
		cat >"/etc/X11/gdm/Sessions/$n" <<__EOF__
#!/bin/sh
exec /etc/X11/Xsession $n
__EOF__
		chmod 755 "/etc/X11/gdm/Sessions/$n"
	done
fi
