#!/bin/sh
# <BEGIN COPYRIGHT>
# This file is part of the "Bad Penguin" GNU/Linux distribution
# Copyright (C) 1997-98-99 by Antonio GALLO aka AGX
# Home Page at ......: http://www.badpenguin.org
# Home Page at ......: http://www.linux.it/~agx/
# e-mail contact ....: mailto:agx@linux.it	mailto:agx@geocities.com
# This program is distributed under the GNU General Public License
# You are not allowed to remove the copyright notice
# <END COPYRIGHT>

# Register a WM into BP
# AGX application register 0.001 - 19980115
# AGX application register 0.010 - 19980210
# AGX application register 0.100 - 19980412
# AGX window manager register 0.200 - 19990613
# 1999-11-04, Version 1.6.0 by AGX



# --- Parameters Checking ---
#   Usage: install-windowmanager <wm_fullpath> <wm_name>
# Example: install-windowmanager /usr/bin/enlightenment  enlightenment
if [ "$1" = "" -o "$2" = "" ]; then
  echoc RED "install-windowmanager: (Usage) install-windowmanager <wm_fullpath> <wm_name>"
  exit 1
fi  
WM_PATH=$1
WM_NAME=$2



# Sanity Checks
if [ ! -f /etc/sysconfig/WINDOW-MANAGERS ]; then
  > /etc/sysconfig/WINDOW-MANAGERS
fi
if [ ! -f /root/.WINDOWMANAGER ]; then
  > /root/.WINDOWMANAGER
fi
if [ ! -f /etc/skel/.WINDOWMANAGER ]; then
  > /etc/skel/.WINDOWMANAGER
fi
TEMPSCRIPT=/root/.temp$$.install-windowmanager


# Register Window Manager
WM_INSTALL=1
grep $WM_NAME /etc/sysconfig/WINDOW-MANAGERS >/dev/null 2>/dev/null
if [ $? -eq 1 ]; then
  echo "- Registering $WM_NAME as Window Manager"
  echo "$WM_NAME:$WM_PATH" >> /etc/sysconfig/WINDOW-MANAGERS
else
  echo "- Window-Manager already registered."
fi



# Check the default WM
OLDWM="`cat /root/.WINDOWMANAGER`"
if [ ! "$OLDWM" = "$WM_PATH" ]; then
  sleep 1
  dialog --yesno "Vuoi installare $WM_NAME come Window Manager predefinito ?" 7 70  2>$TEMPSCRIPT
  WM_INSTALL=$?
  rm -f $TEMPSCRIPT
else
  echo "- $WM_NAME is already the default window manager."
  WM_INSTALL=1  
fi


# Install as the default Window Manager
if [ $WM_INSTALL -eq 0 ]; then
  echo "- Installing $WM_NAME as the default window manager."
  echo $WM_PATH > /etc/skel/.WINDOWMANAGER
  echo $WM_PATH > /root/.WINDOWMANAGER
  
  # Schedule Install menu 
  SK_NAME="/var/spool/badpenguin/ZZ-run-install-menu.post-install"
  if [ ! -f $SK_NAME ]; then
    echo "#!/bin/sh" > $SK_NAME
    echo "/usr/local/sbin/install-menu" >> $SK_NAME
    echo "- Window manager's menu' will be update later."
  fi
  exit 0
fi	
