#!/bin/sh
# Convenience script to start kommander gui-script from the commandline
#
# (c) 2005 Bart Cornelis <cobaco AT skolelinux no>
###############################################################################

display_message() {
  # if we're in a GUI environment, and kdialog is available pop up an error box 
  if (test x != "$DISPLAY"x) && (test -x `which kdialog`) && (which kdialog > /dev/null); then
    kdialog --error "$1";
  # else just output warning
  else
    echo "$1";
  fi;
}

# test if interpreter for gui-script is available 
if ! (which kmdr-executor > /dev/null); then
  display_message "No kmdr-executor present in path -> exiting\n.";
  exit;
else  
  kmdrBinary=`which kmdr-executor`;
fi;


# check if interpreter is executable
if !(test -x $kmdrBinary); then
  display_message "$kmdrBinary is not executable -> exiting":
  exit;
else  
  kmdrVersion="`$kmdrBinary --version | grep "^Kommander Executor:" | sed "s/^.*: *\(.*\)/\1/"`";
fi;

# check if profile-manager kommander script is readable
if !(test -r /usr/share/desktop-profiles/kommander-scripts/profile-manager.kmdr); then
  display_message "/usr/share/desktop-profiles/kommander-sripts/profile-manager.kmdr is missing or unreadable! -> exiting";
  exit;
fi;  

# Check version and run 
#if (test $kmdrVersion = 1.0) || (echo $kmdrVersion | grep "^0."); then
  $kmdrBinary /usr/share/desktop-profiles/kommander-scripts/profile-manager.kmdr;
# kommander with new parser ->  known not to work with current script
#else
#  display_message "This script does not yet work with the version of kommander you have installed.\nYou want to try kmdr-executor version 1.0 (kommander packager 1:3.3.2)";
#fi;
