#!/bin/sh

  if [ -r ~/.blackboxrc ]; then
  # cp ~/.blackboxrc ~/.blackboxrc-blackhome-removed
    mv ~/.blackboxrc ~/.blackhome/config/.blackboxrc-blackhome-removed
  fi

  cp ~/.blackhome/config/.blackboxrc ~

  # using startx...
  if [ -r ~/.xinitrc ]; then
    mv ~/.xinitrc ~/.blackhome/config/.xinitrc-blackhome-removed
    cp ~/.blackhome/config/.xinitrc ~
  fi

  # using xdm...
  if [ -r ~/.xsession ]; then
    mv ~/.xsession ~/.blackhome/config/.xsession-blackhome-removed
    cp ~/.blackhome/config/.xsession ~
  fi

# blackhome .Xdefaults are not duplicated in themed .Xdefaults files
# add these in to the base .Xdefaults file
if [ -r ~/.Xdefaults ]; then
  cat ~/.Xdefaults ~/.blackhome/Xdefaults/.Xdefaults-blackhome > ~/.blackhome/Xdefaults/.Xdefaults
  mv ~/.Xdefaults ~/.blackhome/Xdefaults/.Xdefaults-blackhome-removed
else
  cp ~/.blackhome/Xdefaults/.Xdefaults-blackhome ~/.blackhome/Xdefaults/.Xdefaults
fi

# blackhome .Xresources are duplicated in themed .Xresources files
# there will be override warnings from X except for newly-installed themes
# but without this there are no base .Xresources.
if [ -r ~/.Xresources ]; then
  cat ~/.Xresources ~/.blackhome/Xdefaults/.Xresources-blackhome > ~/.blackhome/Xdefaults/.Xresources
  mv ~/.Xresources ~/.blackhome/Xdefaults/.Xresources-blackhome-removed
else
  cp ~/.blackhome/Xdefaults/.Xresources-blackhome ~/.blackhome/Xdefaults/.Xresources
fi

# gtkrc resources - use home dir resources if found
if [ -r ~/.gtkrc ]; then
  cp ~/.gtkrc ~/.blackhome/Xdefaults/gtk/.gtkrc-blackhome-removed
  # the existing .gtkrc should have 'include <path to home dir>.gtkrc-mine'
  #in it...
else
  # make one up
  echo "include ".gtkrc.mine"" > ~/.gtkrc
fi

if [ -r ~/.gtkrc.mine ]; then
  cp ~/.gtkrc.mine ~/.blackhome/Xdefaults/gtk/gtkrc-color
  mv ~/.gtkrc.mine ~/.blackhome/Xdefaults/gtk/.gtkrc.mine-blackhome-removed
else
  mv ~/.blackhome/Xdefaults/gtk/gtkrc-blackhome ~/.blackhome/Xdefaults/gtk/gtkrc-color
fi

# install supplied themes
~/.blackhome/config/install theme alpha alpha.jpg
~/.blackhome/config/install theme omega omega.jpg
~/.blackhome/config/install image alpha sunset.jpg
~/.blackhome/config/install image omega btk05.jpg
~/.blackhome/config/install xpm alpha cream_wove.xpm
~/.blackhome/config/install xpm alpha parch.xpm
~/.blackhome/config/install xpm omega dull_metal_tile.xpm
~/.blackhome/config/install xpm omega bright_metal_tile.xpm
~/.blackhome/config/install xpm omega bg_waffle.xpm

# customise the app defaults and menu colours for supplied themes
mv -f ~/.blackhome-custom-extras/Xdefaults/gtk/gtkrc-alpha ~/.blackhome/Xdefaults/gtk
mv -f ~/.blackhome-custom-extras/Xdefaults/gtk/gtkrc-omega ~/.blackhome/Xdefaults/gtk
mv -f ~/.blackhome-custom-extras/Xdefaults/.*omega ~/.blackhome/Xdefaults
mv -f ~/.blackhome-custom-extras/Xdefaults/.*alpha ~/.blackhome/Xdefaults
mv -f ~/.blackhome-custom-extras/app-defaults/*omega ~/.blackhome/app-defaults
mv -f ~/.blackhome-custom-extras/app-defaults/*alpha ~/.blackhome/app-defaults
mv -f ~/.blackhome-custom-extras/menus/omega.menu ~/.blackhome/menus
mv -f ~/.blackhome-custom-extras/menus/alpha.menu ~/.blackhome/menus

# required to set up initial gtk theme list (if there are any...)
~/.blackhome/control/preprocess.sh

echo
echo "      blackhome-0.3.4.2 by Will 18; 1999-2007.
      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., 675 Mass Ave, Cambridge, MA 02139, USA.
      See .blackhome/COPYING for full details. "
echo
echo "blackhome new user setup completed." 

missing=0
echo
for x in wmsetbg bsetbg bsetroot xsetroot Esetroot xv
do
  $x -notanoption 1> /dev/null 2> blackhome_output
  var=$(cat blackhome_output | grep "command not found")

  if [ -n "$var" ]; then
    missing=$(( $missing + 1 ))
    echo $var
  fi
done
		      
if [ $missing -ne 0 ]; then
  echo
  echo "The above display utilities were not found. Some styles use them."
  echo "You may wish to either install them or change the display command"
  echo "in the .blackhome/control/<themeName>.sh file if a style background"
  echo "does not load."
fi  

less 1> /dev/null 2> blackhome_output
var=$(cat blackhome_output | grep "command not found")

if [ -n "$var" ]; then
  echo "the GNU utility 'less' was not found. Blackhome's GTK style"
  echo "feature will not operate correctly. Get less from http://gnu.org"
fi

rm blackhome_output blackhome
