#!/bin/sh
# Copyright  1997, Guylhem Aznar (guylhem@danmark.linux.eu.org)
# Freely distribuable under the terms of the GPL license .

AFDIR=$HOME/.step

# Update desktop-backgrounds-pictures ?

if grep -q ^update-pictures-at-every-startup $AFDIR/OPTIONS
then
 $AFDIR/make-picturesmenu
fi

# Update steprc ?

if grep -q ^update-steprc-at-every-startup $AFDIR/OPTIONS
then
 # Yes, so let's check everything is here and then do the work !
 if [ ! -d $AFDIR ] ; then
  echo "No directory $AFDIR, exiting !"
  exit
 fi
 if [ ! -f $AFDIR/afterstep.base ] ; then
  echo "No configuration file $AFDIR/afterstep.base, exiting !"
  exit
 fi
 if [ ! -f $AFDIR/afterstep.look ] ; then
  echo "No configuration file $AFDIR/afterstep.look, exiting !"
  exit
 fi
 if [ ! -f $AFDIR/afterstep.config ] ; then
  echo "No configuration file $AFDIR/afterstep.config, exiting !"
  exit
 fi
 if [ ! -f $AFDIR/afterstep.modules ] ; then
  echo "No configuration file $AFDIR/afterstep.modules, exiting !"
  exit
 fi
 if [ ! -f $AFDIR/afterstep.menus ] ; then
  echo "No configuration file $AFDIR/afterstep.menus, exiting !"
  exit
 fi
 if [ ! -d $AFDIR/start ] ; then
  echo "No directory $AFDIR/start, exiting !"
  exit
 fi
 if [ ! -f $AFDIR/afterstep.bindings ] ; then
  echo "No configuration file $AFDIR/afterstep.bindings, exiting !"
  exit
 fi
 #
 # Add startmenu options
 $AFDIR/make-startmenu
 #
 # Merge config files
 echo "#Do not modify ! It's rebuilt at every startup !" > $AFDIR/steprc
 cat $AFDIR/afterstep.base >> $AFDIR/steprc
 cat $AFDIR/afterstep.look >> $AFDIR/steprc
 cat $AFDIR/afterstep.config >> $AFDIR/steprc 
 cat $AFDIR/afterstep.modules >> $AFDIR/steprc
 cat $AFDIR/afterstep.menus >> $AFDIR/steprc
 cat ~/.step/tmp/startmenu-made >> $AFDIR/steprc
 cat $AFDIR/afterstep.bindings >> $AFDIR/steprc
fi

# Load default root background ?

if grep -q ^load-background-at-every-startup $AFDIR/OPTIONS
then 
 if [ ! -f $AFDIR/background.picture ] ; then
  if [ -f $AFDIR/background.color ] ; then
   xsetroot -solid `cat $AFDIR/background.color`
  fi
 else
  xli -onroot `cat $AFDIR/background.picture`
 fi
fi

# Then finally load afterstep

afterstep
