#!/bin/bash
############################################################
#                                                          #
# lvu - view Lunar module information                      #
#                                                          #
############################################################
# Original gaze written by Brian Peterson                  #
# Copyright 2001 by Brian Peterson                         #
############################################################
# gaze is part of the sorcery spell management utility     #
# This version contains none of Brian Peterson's source    #
# Copyright 2001 by Kyle Sallee                            #
############################################################
#                                                          #
# this WAS the gaze script of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer       #
# available with GPL license. Since this script was taken  #
# before licensing scheme change, no legal problems I      #
# guess.                                                   #
#                                                          #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=)     #
# Kagan Kongar <kongar@tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Parts Copyrighted Jason Johnston 2002 under GPLv2        #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
# Parts Copyrighted Auke Kok 2003 under GPLv2              #
#                                                          #
############################################################

help() {
cat << EOF
Invoke lvu with desired command followed by arguments.
Please note that anything in brackets [ ] is optional.

Command     Arguments      Description

what        module         display a module's description
where       module         display a module's section
cd          module         change directory to module and execs a new shell
alien                      discover untracked files
from        path/file      discover what installed a file
leafs                      display installed modules that have no explicit
                               dependencies on them
orphans                    display installed modules that are missing
                               dependancies
held                       display held modules
exiled                     display exiled modules

search      "phrase"       searches module's long descriptions for phrase.
service     port|acronym   displays module's that provide that service

website     module         display a module's website
install     module         display an install log
size        [module]       find and show installed size of a module
                               or ALL (slow)
installed   [module]       display installed modules/version of module
compile     module         display a compile log
compiler    module         display the compiler version used
links       module         display a list of modules that this module links to
sources     [module]       display source files for a module
urls        [module]       display all URLs for a module
maintainer  module         display maintainer for a module
version     module         display version of module in moonbase

sum         [module]       display checksums
md5sum      [module]       display md5sums

export                     make snapshot of box's configuration.
import                     snapshot restore snapshot.

section     [section]      display moonbase sections
moonbase                   display text listing of the moonbase
html                       display html listing of the moonbase
updatelog                  display summary log of previous lunar update
activity                   display main log file

newer       20020521       display available modules newer than May 21, 2002
older       20010521       display modules installed before May 21, 2001

voyeur      [delay|module] peak into module compilation

pam                        display installed modules that are Linux-PAM aware

depends     module         displays the modules that explicitly or
                               recursively depend on this module.
tree        module         displays a tree of the module's dependencies
eert        module         displays a tree of the module's reverse dependencies

\$MODULE_SCRIPT module      will print the module script for that module
EOF
}


export_snapshot()  {
  SOURCE_DIRECTORY=$BUILD_DIRECTORY/snapshot
  mk_source_dir          $SOURCE_DIRECTORY
  cp  -a  /etc           $SOURCE_DIRECTORY
  cp  -a  $CONFIG_CACHE  $SOURCE_DIRECTORY

  for  LINE  in  $(cat  $MODULE_STATUS) ;  do
    MODULE=$(echo  $LINE  |  cut  -d  :  -f1)
     STATUS=$(echo  $LINE  |  cut  -d  :  -f2)
    if  [  "$STATUS"  ==  "installed"  ];  then
      echo  $MODULE  >>  /usr/src/snapshot/install
    fi
  done

  SNAPSHOT="/root/snapshot-$HOSTNAME-$(date  -u  +%Y%m%d).tar.bz2"

  cd  $BUILD_DIRECTORY
  tar    -c  snapshot     |
  bzip2  -9  >  $SNAPSHOT
  rm_source_dir          $SOURCE_DIRECTORY
  echo  "$SNAPSHOT created."
}


import_snapshot()  {
          SNAPSHOT=$1
  SOURCE_DIRECTORY=$BUILD_DIRECTORY/snapshot

  if  [  -f  "$1"  ];  then
    cd  $BUILD_DIRECTORY
    mk_source_dir          $SOURCE_DIRECTORY

    bzcat $SNAPSHOT  |  tar  -x
    cd  $SOURCE_DIRECTORY

    for  LINE  in  $(cat  install);  do
      push_install_queue  $LINE
    done
    report  $INSTALL_QUEUE  "Install Queue"

    cp  -ai  local  /etc/lunar
    cp  -ai  etc    /

    cd  /
    rm_source_dir  $SOURCE_DIRECTORY

  else
    message  "Unable to find snapshot  \"$SNAPSHOT\""
    false
  fi
}


checksum() {
  for FILE in $(cat $1 | files) ; do
    sum -s  $FILE
  done
}


md5sum_files() {
  for FILE in $(cat $1 | files) ; do
    md5sum  $FILE
  done
}


alien() {

  message  "In a few minutes I will print files found on this disk"
  message  "that were not installed by lunar.  This is not a"
  message  "security feature!  Files could still be lurking"
  message  "undetected on this box."

  rm    -f  /tmp/lvu.found
  rm    -f  /tmp/lvu.known

  message  "Discovering ambient files..."
  find  $TRACKED  |  files  |  filter  "$EXCLUDED"  |  sort  >/tmp/lvu.found
 
  message  "Discovering installed files..."
  cat  $INSTALL_LOGS/*  |  files  |  sort  >  /tmp/lvu.known

  diff  -B  -a  -d  /tmp/lvu.found  /tmp/lvu.known  |
  grep  -v  "^> "                                     |
  grep      "^< "                                     |
  cut  -c  3-                                         |
  filter  "$PROTECTED"

  rm  -f  /tmp/lvu.found
  rm  -f  /tmp/lvu.known

}


lvu_catalog()  {
  echo  "Lunar Moonbase for $(date  -u)"

  ((  COUNT=0  ))

  for  SECTION  in  $(list_sections);  do
    echo 
    echo  "-------------------------------------------------"
    echo  "SECTION:  $SECTION"  
    echo  "-------------------------------------------------"
    for  MODULE  in  $(list_modules $SECTION);  do
      echo  $MODULE
      ((  COUNT++  ))
    done
  done

  echo
  echo  "Total modules:  $COUNT"
}


lvu_catalog_html()  {

  echo  "<html><head><title>Lunar Moonbase for $(date  -u)</title>"
  echo  "<meta http-equiv=\"Pragma\" content=\"no-cache\"></head>"
  echo  "<body>"

  echo  "<table align=\"center\" border=5>"

  echo  "<tr><th colspan=5><font color=maroon size=+1>"
  echo  "Lunar Moonbase<br>$(date  -u)"
  echo  "</font></th></tr>"

  echo  "<tr>"
  echo  "<th>Module</th>"
  echo  "<th>Version</th>"
  echo  "<th>Updated</th>"
  echo  "<th>Website</th>"
  echo  "<th>Maintainer</th>"
  echo  "</tr>"

  ((  COUNT=0  ))

  for  SECTION  in  $(list_sections);  do
    ((  SECTION_COUNT=0 ))
    echo  "<tr><th colspan=5><font color="maroon">$SECTION</font></th></tr>"
    for  MODULE  in  $(list_modules $SECTION);  do
      (
        run_details $MODULE &> /dev/null
        echo  "<tr>"
        if  [  "$MODULE"  ==  "linux"  ]   ||
            [  "$MODULE"  ==  "glibc"  ];  then
            BOLD="<b>"
          UNBOLD="</b>"
        else
          unset    BOLD
          unset  UNBOLD
        fi
        if  [  ${#MODULE}  -gt  15  ];  then
          MODULE="<font size=-1>$MODULE</font>"
        fi
        echo  "<td>$BOLD $MODULE $UNBOLD</td>"
        echo  "<td><font size=-1>$BOLD $VERSION $UNBOLD</font></td>"
        echo  "<td><font size=-1>$UPDATED</font></td>"

        WEBSITE=$WEB_SITE
        if    [  ${#WEB_SITE}  -lt 20  ];  then
            SHRINK="<font size=-1>"
          UNSHRINK="</font>"
        elif  [  ${#WEB_SITE}  -lt 30  ];  then
            SHRINK="<font size=-2>"
          UNSHRINK="</font>"
        else
           WEBSITE="$(echo  $WEB_SITE  |  cut  -c-30)..."
            SHRINK="<font size=-3>"
          UNSHRINK="</font>"
        fi

        if  [  "$WEB_SITE"  !=  "unknown"  ];  then
          echo  "<td> $SHRINK"
          echo  "<a href=\"$WEB_SITE\" target=\"_blank\">$WEBSITE</a>"
          echo  "$UNSHRINK </td>"
        else
          echo  "<td></td>"
        fi

        if  [  -z  "$MAINTAINER"  ];  then
          MAINTAINER="maintainer@lunar-linux.org"
        fi

        echo  "<td><font size=-1>"
        echo  "<a href=\"mailto:$MAINTAINER\">$MAINTAINER</a>"
        echo  "</font></td>"
        echo  "</tr>"
      )
      ((  COUNT++  ))
      ((  SECTION_COUNT++ ))
    done
    echo "<tr><th colspan=5>Modules in $SECTION section: $SECTION_COUNT</th></tr>"
  done

  echo  "<tr><th colspan=5>Total modules: $COUNT</th></tr>"
  echo  "</table></body></html>"
}


newer()  {
  [ -z "$1" ] && return 1      
  DATE=$1
  [ "$DATE" -lt "20010101" ] && return 1        
  [ "$DATE" -gt "20310101" ] && return 1
  for MODULE in $(list_moonbase) ; do
    run_details $MODULE
    if [ $ENTERED -gt $DATE ] ; then
      echo $MODULE
    fi
  done
}


older()  {
  [ -z "$1" ] && return 1      
  DATE=$1
  [ "$DATE" -lt "20010101" ] && return 1        
  [ "$DATE" -gt "20310101" ] && return 1        
  for  LINE  in $(cat $MODULE_STATUS_BACKUP) ; do
    LIN_DATE=$(echo  $LINE  |  cut  -d  :  -f2)
    if  [  $LIN_DATE  -gt  $DATE  ]  2>/dev/null;  then
      true
    else
      echo  $LINE  |  cut  -d  :  -f1
    fi
  done
}


show_module_component()  {
  COMPONENT=$1
     MODULE=$2
    SECTION=$(find_section $MODULE)
  if [ -e $MOONBASE/$SECTION/$MODULE/$COMPONENT ] ; then
    cat $MOONBASE/$SECTION/$MODULE/$COMPONENT
  fi
}


find_lining()  {
  for  FILE in $(ls  /var/lock/lining*  2>/dev/null);  do
    if  ps  $(cat  $FILE  2>/dev/null)  |  grep  -q  lin;  then
      echo  $FILE  |  sed  "s:/var/lock/lining.::"
      return  0
    fi
  done
  false
}


peak_lining()  {
  if  [  -f     /var/lock/lining.$1   ]            &&
      ps  $(cat  /var/lock/lining.$1  2>/dev/null)  |
      grep  -q  lin                                &&
      [  -f  /tmp/$1.compile.log  ]
  then
    nice  -n  +20                  \
    tail  -f  /tmp/$1.compile.log  \
          --follow=name            \
          --pid=$(cat /var/lock/lining.$1)  2>/dev/null
  fi
}


activate_voyeur()  {
  if  [  -n  "$1"  ]  &&
      !  find_section  $1  >  /dev/null
  then  ((  DEFAULT_DELAY  =  $1  *  60  ))
        shift  1
  fi

  for  MODULE  in  $@;  do
    peak_lining  $MODULE
  done

  DEFAULT_DELAY=${DEFAULT_DELAY:=60}

  while  true;  do
    if    !  ACTIVE_MODULE=$(find_lining) ;  then
      message  "${MESSAGE_COLOR}Waiting"       \
               "${DEFAULT_DELAY}"              \
               "seconds for a lin to begin."  \
               "${DEFAULT_COLOR}"
      for  ((  DELAY=DEFAULT_DELAY  ;  DELAY > 0  ;  DELAY--  )); do
        if  ACTIVE_MODULE=$(find_lining);  then
          break
        else
          sleep 1
        fi
      done
    fi

    if    [  -z  "$ACTIVE_MODULE"  ];  
    then  break
    else  peak_lining  $ACTIVE_MODULE
    fi
  done
}


show_leafs()  {
  for  MODULE  in  $(cat  $MODULE_STATUS  |  cut  -d :  -f1) ;  do
    if    !  cut  -d :  -f2-  $DEPENDS_STATUS  |
             grep             "^$MODULE:"       |
             grep  -q         ":on:"
    then     echo   $MODULE
    fi
  done
}


show_orphans()  {
  for MODULE in $(cat  $MODULE_STATUS  |  cut  -d :  -f1) ; do
    for  LINE  in  $(grep  "^${MODULE}:"  $DEPENDS_STATUS) ;  do
       DEPENDS=$(echo  $LINE  |  cut  -d :  -f2)
        STATUS=$(echo  $LINE  |  cut  -d :  -f3)
      OPTIONAL=$(echo  $LINE  |  cut  -d :  -f4)
      if ! module_installed $DEPENDS ; then
        if [ "$OPTIONAL" == "required" ]; then
          echo "$MODULE: $DEPENDS is missing"
	fi
      fi
    done
  done
}


show_depends()  {
  if  !  echo  "$DONE"  |  grep  -q  "$1";  then
    DONE="$DONE  $1"

    for  LINE  in  $(grep  ":$1:"  $DEPENDS_STATUS) ; do
       MODULE=$(echo  $LINE  |  cut  -d :  -f1)
      STATUS=$(echo  $LINE  |  cut  -d :  -f3)

      if    [  "$STATUS"  ==  "on"  ]
      then  echo          $MODULE
            show_depends  $MODULE
      fi

    done
  fi
}


# function: show_tree
# usage: show_tree <module>
# purpose: show a tree of the module's dependencies (recursive)
function show_tree() {
  [[ -z "$1" ]] && help && exit 1

  FORMATTED_MODULE="$1"
  MODULE=$(echo $1 | sed 's/[()]//g')
  MODULE_DIR="${MOONBASE}/$(find_section ${MODULE})/${MODULE}"
  DEPENDS_FILE="${MODULE_DIR}/DEPENDS"

  if [ ! -e "${MODULE_DIR}/DETAILS" ] ; then
    echo -e "${PROBLEM_COLOR}! ${MODULE} not found !${DEFAULT_COLOR}"
    return 1
  fi

  # purpose: Create the tree for displaying
  set_tree() {
    TREE=""
    for (( i=0; i<${INDENT}; i++ )); do
      TREE="${TREE}|-->"
    done
    TREE=$(echo ${TREE} | sed 's/-->|/   |/g')
    echo -en "${TREE}${MODULE_COLOR}${FORMATTED_MODULE}${DEFAULT_COLOR}: "
  }

  # purpose: Retrieve all dependencies
  get_depends() {
    NON_OPTIONAL='/^[[:blank:]]*#/! s/.*\<depends\>[[:blank:]]*\([0-9a-zA-Z"+_-]*\).*/\1/p'
    OPTIONAL='/^[[:blank:]]*#/! s/.*\<optional_depends\>[[:blank:]]*\([0-9a-zA-Z"+_-]*\).*/(\1)/p'
    DEPENDS=$(sed -n "${NON_OPTIONAL}"'; '"${OPTIONAL}" ${DEPENDS_FILE} | sed 's/"//g' | tr "\n" " ")
    for dep in ${DEPENDS}
    do
      adep=$(echo ${dep} | tr -d "()")
      if grep "^${adep}:.*:installed:" ${MODULE_STATUS} >/dev/null
      then
        echo -ne "${FILE_COLOR}${dep} "
      elif grep "^${adep}:.*:held:" ${MODULE_STATUS} >/dev/null
      then
        echo -ne "${LRM_COLOR}${dep} "
      else
        echo -ne "${PROBLEM_COLOR}${dep} "
      fi
    done
    echo -e "${DEFAULT_COLOR}"
  }

  # purpose: Get reverse dependencies
  get_reverse_depends() {
    DEPENDS=$(grep :${MODULE}: "$DEPENDS_STATUS" | cut -d':' -f1 | tr "\n" " ")
    [[ -n "${DEPENDS}" ]] && echo -e "${FILE_COLOR}${DEPENDS}${DEFAULT_COLOR}"
  }

  # purpose: recurse
  recurse() {
    (( INDENT++ ))
    for i in ${DEPENDS}; do
      show_tree $i
    done
    (( INDENT-- ))
  }

  [[ -z "${INDENT}" ]] && INDENT=0

  set_tree
  if [[ -z "${REVERSE}" ]]; then
    if [[ -x "${DEPENDS_FILE}" ]]; then
      get_depends
      recurse
    else
      echo "No dependencies"
    fi
  else
    get_reverse_depends
    if [[ -z "${DEPENDS}" ]]; then
      echo "No reverse dependencies"
    else
      recurse
    fi
  fi
}


show_urls() { (
  # function overrides:
  call_wget() { echo $@ ; }
  guess_filename() { false ; }
  file() { return ; }
  mv() { return ; }
  get_cvs() { return ; }
  testpack() { return ; }
  connect() { return ; }
 
  SILENT=on
  VERBOSE=off
  FUZZY=off
  EXHAUSTIVE=off
  CLEAR_CACHE=off

  if [ -z "$1" ] ; then
    MODULES=$(list_moonbase|sort)
  else
    MODULES=$1
  fi
  
  for MODULE in $MODULES ; do
    download_module $MODULE
  done
) }


main()  {
  case $1 in
    html)
      lvu_catalog_html
      ;;
      
    export)
      export_snapshot
      ;;
      
    import)
      import_snapshot $2
      ;;
      
    section)
      if [ -n "$2" ] ; then
        list_modules $2
      elif [ -z "$2" ] ; then
	list_sections
      fi
      ;;
      
    alien)
      alien
      ;;

    from)
      cd $INSTALL_LOGS
      grep $2 *
      ;;
      
    newer)
      newer $2
      ;;
      
    older)
      older $2
      ;;
      
    moonbase)
      lvu_catalog | view_file
      ;;

    leafs)
      show_leafs | sort | uniq
      ;;
      
    orphans)
      show_orphans | sort | uniq
      ;;
      
    updatelog)
      if [ -e /var/log/lunar/update ]; then
        view_file /var/log/lunar/update
      else
        echo "No update log available."
      fi
      ;;

    activity)
      if [ -e $ACTIVITY_LOG ]; then
        view_file $ACTIVITY_LOG
      else
        echo "No update log available."
      fi
      ;;

    installed)
      if [ -z "$2" ] ; then
        view_file $MODULE_STATUS
      elif [ -n "$(installed_version $2)" ] ; then
        echo "$(installed_version $2)"
      else
        message "$2 is not installed"
	false
      fi
      ;;

    held)
      grep ":held:" $MODULE_STATUS | cut -d: -f1
      ;;

    exiled)
      grep ":exiled:" $MODULE_STATUS | cut -d: -f1
      ;;
		
    sum)
      if [ -n "$2" ] ; then
        if ! checksum  "$INSTALL_LOGS/$2-$(installed_version $2)" ; then
          checksum  "$INSTALL_LOGS/*"
	fi
      fi
      ;;
	  
    md5sum)
      if [ -n "$2" ] ; then
        if ! md5sum_files "$INSTALL_LOGS/$2-$(installed_version $2)" ; then
	  md5sum_files  "$INSTALL_LOGS/*"
        fi
      fi
      ;;

    voyeur)
      shift 1
      activate_voyeur $@
      ;;

    pam)
      find_pam_aware
      ;;
     
    sources)
      sources $2
      ;;

    urls)
      show_urls $2
      ;;

    maintainer)
      if run_details $2 ; then
        if [ -n "$MAINTAINER" ] ; then  
          echo $MAINTAINER
        else
          echo maintainer@lunar-linux.org
        fi
      fi
      ;;
      
    DETAILS)
      show_module_component $1 $2
      ;;
      
    DEPENDS)
      show_module_component $1 $2
      ;;
      
    CONFIGURE)
      show_module_component $1 $2
      ;;
      
    CONFLICTS)
      show_module_component $1 $2
      ;;
      
    PRE_BUILD)
      show_module_component $1 $2
      ;;
      
    BUILD)
      show_module_component $1 $2
      ;;
      
    POST_BUILD)
      show_module_component $1 $2
      ;;
      
    POST_INSTALL)
      show_module_component $1 $2
      ;;
      
    PRE_REMOVE)
      show_module_component $1 $2
      ;;
      
    POST_REMOVE)
      show_module_component $1 $2
      ;;
      
    search)
      for SECTION in $(list_sections) ; do
        for MODULE in $(list_modules $SECTION) ; do
        (
          run_module_file $MODULE DETAILS | grep -q -i "$2" &&
          echo "$SECTION/$MODULE"
        )
	done
      done
      ;;
      
    service)
      for SECTION in $(list_sections) ; do
        for MODULE in $(list_modules $SECTION) ; do
          if [ -f $MOONBASE/$SECTION/$MODULE/services ] && 
              grep -q -i "$2" $MOONBASE/$SECTION/$MODULE/services ; then
            echo "$SECTION/$MODULE"
          fi
	done
      done
      ;;
      
    depends)
      show_depends "$2" | sort | uniq
      ;;
      
    website)
      if [ -z "$2" ] ; then
        return 1
      else
        if run_details $2 ; then
          if [ -n "$WEB_SITE" ] ; then
            echo $WEB_SITE
          else
            echo "http://www.lunar-linux.org"
	  fi
        fi
      fi
      ;;
      
    version)
      if [ -n "$2" ] ; then
        if run_details $2 ; then
  	  echo $VERSION
	fi
      fi
      ;;
      
    size)
      if [ -z "$2" ] ; then
        MODULES=$(cat $MODULE_STATUS | cut -d: -f1 | sort)
        for MODULE in $MODULES ; do
          echo $MODULE $(find_module_size $MODULE)
        done
      else
        if module_installed $2 ; then
          find_module_size $2
        else
          message "${PROBLEM_COLOR}$MODULE not installed${DEFAULT_COLOR}"
        fi
      fi
      ;;
      
    tree)
      show_tree "$2"
      ;;
      
    eert)
      REVERSE="on"
      show_tree "$2"
      ;;

    compile)
      if run_details $2 ; then
        if [ -f $COMPILE_LOGS/$2-$(lvu version $2).bz2 ] ; then
          view_file $COMPILE_LOGS/$2-$(lvu version $2).bz2
        else
          VERSION=$(installed_version $2)
          view_file $COMPILE_LOGS/$2-$(installed_version $2).bz2 \
             "Compile log for $2 does not exist"
        fi
      fi
      ;;
	      
   install)
     if run_details $2 ; then
       view_file $INSTALL_LOGS/$2-$(installed_version $2) \
           "Install log for $2 does not exist"
     fi
     ;;

   compiler)
     if [ ! -z "$2" ] ; then
       if run_details $2 ; then
         if [ ! -e $INSTALL_LOGS/$2-$(installed_version $2) ] ; then 
           echo "Install log for $2 does not exist" 
           return 1
         else
           cat $INSTALL_LOGS/$2-$(installed_version $2) | while read LINE ; do
             if file $LINE | grep -q "ELF " ; then
               echo -n "$LINE "
               strings -a $LINE | grep GCC: | sort -r | head -n 1
             fi  
           done
         fi
       fi
     fi
     ;;

   links)
     if [ -z "$2" ] ; then
       return 1
     else
       for FILE in $(lvu install $2) ; do
         TYPE=$(file $FILE | cut -d' ' -f2)
         if [[ "$TYPE" == "ELF" ]] ; then
           BINARIES="$BINARIES $FILE"
           verbose_msg "found binary: \"$FILE\""
         fi
       done
       for BINARY in $BINARIES ; do
         LINKSTO=$(ldd $BINARY | cut -d' ' -f3)
       done
       for LINK in $LINKSTO ; do
         lvu from $LINK | cut -d: -f1
       done | sort | uniq
     fi
     ;;
     
   what)
     if [ ! -z "$2" ] ; then
       if run_details $2 ; then
         run_module_file $2 DETAILS
       fi
     fi
     ;;
	   
   where)
     if [ ! -z "$2" ] ; then
       if run_details $2 ; then
         echo $(find_section $2)
       fi
     fi
     ;;

   cd)
     if [ ! -z "$2" ] ; then
       if run_details $2 ; then
         cd $MOONBASE/$(find_section $2)/$2
         $SHELL
       fi
     fi
     ;;

   *)
     help
     ;;

   esac
 
}



. /etc/lunar/config

GETOPT_ARGS=$(getopt -q -n lvu -o "dhv" -l "debug,help,verbose" -- "$@")

if [ -z "$?" ] ; then
  help | view_file
  exit
else
  eval set -- $GETOPT_ARGS
  export IFS="$STANDARD_IFS"
  
  set_priority
  
  while true ; do
    case "$1" in
      -d|--debug       ) (( LUNAR_DEBUG++ )) ; export LUNAR_DEBUG ; shift   ;;
      -h|--help        ) help ; exit                                        ;;
      -v|--verbose     ) export VERBOSE="on" ;                      shift   ;;
      --) shift ; break ;;
      *) help ; break ;;
    esac
  done

  main $@
fi



