#!/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>

# Install a X Session Manager into BP
# AGX application register 0.001 - 19980115
# AGX X session manager register 0.200 - 19990701
# 1999-11-04, Version 1.6.0 by AGX


# --- Parameters Checking ---
#   Usage: install-xsession <sm_fullpath>
# Example: install-xsession /usr/bin/panel
if [ "$1" = "" ]; then
  echoc RED "install-xsession: (Usage) install-xsession <wm_fullpath>"
  exit 1
fi  
WM_PATH=$1


# Sanity Checks
if [ ! -f /root/.XSESSION ]; then
  echo "/usr/X11R6/bin/xterm -ls" > /root/.XSESSION
fi
if [ ! -f /etc/skel/.WINDOWMANAGER ]; then
  echo "/usr/X11R6/bin/xterm -ls" > /root/.XSESSION
fi
TEMPSCRIPT=/root/.temp$$.install-windowmanager


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


# Install as the default Window Manager
if [ $WM_INSTALL -eq 0 ]; then
  echo "- Installing $WM_PATH as the default session manager."
  echo $WM_PATH > /etc/skel/.XSESSION
  echo $WM_PATH > /root/.XSESSION 
  exit 0
fi	
