#! /bin/sh

#################################################################
# This is a "simple" script which is intended to be run by rpm
# as a post install function to look at the system where wdm is
# being installed and create Xclients and wdm-config files which
# reflect the window managers available on that system.

#    This software is Copyright (C) 1998 by Gene Czarcinski.
# This software falls under the GNU Public License. Please read
#              the COPYING file for more information
#################################################################

save_ifs="$IFS"
IFS=:
path=$PATH:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/usr/kde/bin:/opt/kde/bin

WMLIST=""

# entry for WindowMaker
rc_word=RunWM
WMAKER_PATH=""
wmakercm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/wmaker; then
        WMAKER_PATH=$rc_dir/$rc_word
	WMLIST=WindowMaker
	wmakercm=""
	break
      fi
    done

# entry for GNOME
rc_word=gnome-session
GNOME_PATH=""
GNOMECM="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        GNOME_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:GNOME"
	GNOMECM=""
	break
      fi
    done

# entry for KDE
rc_word=startkde
STARTKDE_PATH=""
STARTKDECM="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        STARTKDE_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:KDE"
	STARTKDECM=""
	break
      fi
    done

# entry for AfterStep
rc_word=RunWM
AFTERSTEP_PATH=""
afterstepcm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/afterstep; then
        AFTERSTEP_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:AfterStep"
	afterstepcm=""
	break
      fi
    done

# entry for Enlightenment
rc_word=enlightenment
E_PATH=""
ecm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        E_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:Enlightenment"
	ecm=""
	break
      fi
    done

# entry for BlackBox
rc_word=blackbox
BLACKBOX_PATH=""
blackboxcm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        BLACKBOX_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:BlackBox"
	blackboxcm=""
	break
      fi
    done

# entry for icewm
rc_word=icewm
ICEWM_PATH=""
icewmcm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        ICEWM_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:IceWm"
	icewmcm=""
	break
      fi
    done

# entry for qvwm
rc_word=qvwm
QVWM_PATH=""
qvwmcm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        QVWM_PATH=$rc_dir/$rc_word
        WMLIST="$WMLIST:qvwm"
        qvwmcm=""
        break
      fi
    done

# entry for fvwm2
rc_word=fvwm2
FVWM2_PATH=""
fvwm2cm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        FVWM2_PATH=$rc_dir/$rc_word
        WMLIST="$WMLIST:fvwm2"
        fvwm2cm=""
        break
      fi
    done

# entry for twm
rc_word=twm
TWM_PATH=""
twmcm="\\# "
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        TWM_PATH=$rc_dir/$rc_word
        WMLIST="$WMLIST:twm"
        twmcm=""
        break
      fi
    done

WINMGRCM="\\# "

# update wdm-config
	rm -f /etc/X11/wdm/wdm-config
	sed \
		-e "s:#configdir#:/etc/X11/wdm:" \
		-e "s:#bindir#:/usr/X11R6/bin:" \
		-e "s:#SHUTDOWN#:/sbin/shutdown:" \
		-e "s:#logdir#:/var/log:" \
		-e "s:#rundir#:/var/run:" \
		-e "s:#pixmapfile#:vinelogowdm.xpm:" \
		-e "s:#pixmapcomment#::" \
		-e "s/#wmlist#/$WMLIST/" \
		/etc/X11/wdm/wdm-config.in \
		> /etc/X11/wdm/wdm-config
	chmod 600 /etc/X11/wdm/wdm-config

# update Xclients
	rm -f /etc/X11/wdm/Xclients
	sed -e "s:#XRDB#:/usr/X11R6/bin/xrdb:" \
	    -e "s:\#SHELL\#:/bin/bash -login:" \
	    -e "s'#GNOME_PATH#'$GNOME_PATH'" \
	    -e "s'#gnomecm#'$GNOMECM'" \
	    -e "s'#STARTKDE_PATH#'$STARTKDE_PATH'" \
	    -e "s'#startkdecm#'$STARTKDECM'" \
	    -e "s'#WMAKER_PATH#'$WMAKER_PATH'" \
	    -e "s'#wmakercm#'$wmakercm'" \
	    -e "s'#AFTERSTEP_PATH#'$AFTERSTEP_PATH'" \
	    -e "s'#afterstepcm#'$afterstepcm'" \
	    -e "s'#E_PATH#'$E_PATH'" \
	    -e "s'#ecm#'$ecm'" \
	    -e "s'#BLACKBOX_PATH#'$BLACKBOX_PATH'" \
	    -e "s'#blackboxcm#'$blackboxcm'" \
	    -e "s'#ICEWM_PATH#'$ICEWM_PATH'" \
	    -e "s'#icewmcm#'$icewmcm'" \
	    -e "s'#QVWM_PATH#'$QVWM_PATH'" \
	    -e "s'#qvwmcm#'$qvwmcm'" \
	    -e "s'#FVWM2_PATH#'$FVWM2_PATH'" \
	    -e "s'#fvwm2cm#'$fvwm2cm'" \
	    -e "s'#TWM_PATH#'$TWM_PATH'" \
	    -e "s'#twmcm#'$twmcm'" \
	    -e "s'#winmgrcm#'$WINMGRCM'" \
		/etc/X11/wdm/Xclients.in \
		> /etc/X11/wdm/Xclients
	chmod 755 /etc/X11/wdm/Xclients

