#! /bin/bash
#
# INFO : Examine a package
# 
# This script was written to install packages for The System Manager
# and was inspired by the Linux kernel configure script by 
# raymondc@microsoft.com (well, I think it's a neat hack :-)
#
# I'm sure this script can be used for any general purpose installation,
# and I hope it'll catch on big-time.  Let me say that again, louder.
#
# PLEASE USE THIS SCRIPT TO PROVIDE AN INSTALLATION SYSTEM FOR YOUR OWN
# SOFTWARE.  PLEASE USE THIS SCRIPT ON AS MANY UNIX PLATFORMS AS POSSIBLE.
# PLEASE MAKE USE OF IT'S SISTER SCRIPT, REMOVE, TO PROVIDE A WAY TO REMOVE
# YOUR SOFTWARE.
#
# Please send comments/suggestions/bug fixes to S.Herbert@sheffield.ac.uk

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--

set -h

COLOR_BLACK="\033[0;30m"
COLOR_RED="\033[1;31m"
COLOR_GREEN="\033[1;32m"
COLOR_YELLOW="\033[1;33m"
COLOR_BLUE="\033[1;34m"
COLOR_CYAN="\033[1;36m"
COLOR_LIGHT_GREY="\033[0;37m"
COLOR_DARK_GREY="\033[1;30m"
COLOR_WHITE="\033[1;37m"

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = succeed/found/warning/fail (0/1/254/255)
# $2 = general report
# $3 = fail report

Report()
{
  if [ "$1" -eq 255 ]; then
    echo -ne "$COLOR_RED"
    echo -n  "Skipping"
    echo -n  "Skipping : $2" >> $LOG
    if [ -n "$3" ]; then
      echo " ($3)" >> $LOG
    fi
  elif [ "$1" -eq 254 ]; then
    echo -ne "$COLOR_YELLOW"
    echo -n  "Warning "
    echo -n  "Skipping : $2" >> $LOG
    if [ -n "$3" ]; then
      echo " ($3)" >> $LOG
    fi
  elif [ "$1" -eq 1 ]; then
    echo -ne "$COLOR_CYAN"
    echo -n  "Found   "
  else
    echo -ne "$COLOR_GREEN"
    echo -n  "Adding  "
  fi
  echo -ne "$COLOR_LIGHT_GREY"
  echo -n  " : $2"
  if [ ! "$3" = "" ]; then
    echo " ($3)"
  else
    echo ""
  fi
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# no arguements

Usage()
{
  if [ -d .MANIFEST ]; then
    echo "INFO: Examine a package"
    echo "Packages available for examination are :"
    echo ""
    ls .MANIFEST
    echo ""
    echo "Type 'INFO <package> ...' to examine a package or two."
  else
    echo "INFO: directory .MANIFEST does not exist"
  fi
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = author name
# $2 = author address

author()
{
  echo -en "$COLOR_DARK_GREY: $COLOR_LIGHT_GREY"
  echo -e  "Copyright (c) $COLOR_WHITE$1$COLOR_LIGHT_GREY ($2)"
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = comment
# $2 = log it?

comment()
{
  echo -ne "$COLOR_DARK_GREY: COLOR_LIGHT_GREY"
  echo     "$1"
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = directory/file
# $2 = test

depend()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = directory
# $2 = permissions

dir()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# no arguements

endinfo()
{
  exit
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = source
# $2 = dest
# $3 = permissions

file()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = file to link to
# $2 = link

link()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = log comment
# $2 = echo it?

log()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# no arguements

pause()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = required util

require()
{
  echo -en "$COLOR_WHITE"
  echo -n "This module requires '$COLOR_WHITE$1$COLOR_LIGHT_GREY' "
  if which "$1" > /dev/null ; then
    echo "which is installed."
  elif [ -e "$1" ]; then
    echo "which is installed."
  else
    echo "which you need to install."
  fi
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# no arguements

root()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = default hierarchy
# $2 = root directory of package

target()
{
  echo > /dev/null
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# $1 = title

title()
{
  echo -e "$COLOR_DARK_GREY--*-- --*-- --*-- --*-- --*--"
  echo -ne "$COLOR_LIGHT_GREY"
  echo -e  "Examining '$COLOR_WHITE$1$COLOR_LIGHT_GREY'"
  echo -e "$COLOR_DARK_GREY--*-- --*-- --*-- --*-- --*--"
}

#--*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*-- --*--
# this is where the fun begins

# if no arguements, show usage and quit
if [ "$1" = "" ]; then
  Usage
  exit 0
fi

# right, now work through arguements ...
for x in $@ ; do
  if [ -r .MANIFEST/$x ]; then
    Report "0" "$x" "package"
    . .MANIFEST/$x
  else
    Report "255" "$x" "package not found"
  fi
done

# that's it folks!
