#!/usr/bin/bash -login
# configs/wdmReconfig.

#################################################################
# 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:

WMLIST=""

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

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

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

rc_word=startfluxbox
FLUXBOX_PATH="startfluxbox"
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        FLUXBOX_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:FluxBox"
	break
      fi
    done

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

rc_word=startxfce4
XFCE_PATH="startxfce4"
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        XFCE_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:XFCE"
	break
      fi
    done

rc_word=xsession
XSESSION_PATH="xsession"
    for rc_dir in $path; do
      if test -x $rc_dir/$rc_word; then
        XSESSION_PATH=$rc_dir/$rc_word
	WMLIST="$WMLIST:Xsession"
	break
      fi
    done

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

# update wdm-config
	configfile=/etc/X11/wdm/wdm-config
	rm -f $configfile
	sed \
		-e "s:@DMDIR\@:/etc/X11/wdm:" \
		-e "s:@BINDIR\@:@BINDIR@:" \
		-e "s:@SHUTDOWN\@:/sbin/shutdown:" \
		-e "s:@LOGDIR\@:/var/log:" \
		-e "s:@RUNDIR\@:/var/run:" \
		-e "s:@PIXMAPFILE\@:Eagle.xpm:" \
		-e "s:@PIXMAPCOMMENT\@:! :" \
		-e "s:@exec_prefix\@:/usr:" \
		-e "s/@WMLIST\@/$WMLIST/" \
		$configfile.in \
		> $configfile
	chmod 644 $configfile

# update Xclients
	configfile=/etc/X11/wdm/Xclients
	rm -f $configfile
	sed -e "s:@XRDB_PATH\@:/usr/X11R6/bin/xrdb:" \
	    -e "s'@WMAKER_PATH\@'$WMAKER_PATH'" \
	    -e "s'@AFTERSTEP_PATH\@'$AFTERSTEP_PATH'" \
	    -e "s'@BLACKBOX_PATH\@'$BLACKBOX_PATH'" \
	    -e "s'@FLUXBOX_PATH\@'$FLUXBOX_PATH'" \
	    -e "s'@ICEWM_PATH\@'$ICEWM_PATH'" \
	    -e "s'@XFCE_PATH\@'$XFCE_PATH'" \
	    -e "s'@XSESSION_PATH\@'$XSESSION_PATH'" \
	    -e "s'@STARTKDE_PATH\@'$STARTKDE_PATH'" \
		-e "s:@WINMGR_NAME\@::" \
		-e "s:@WINMGR_PATH\@::" \
		$configfile.in \
		> $configfile
	chmod 755 $configfile

