CVS: lunar/var/lib/lunar/functions build.lunar, NONE, 1.1 check.lunar, NONE, 1.1 connect.lunar, NONE, 1.1 init.lunar, NONE, 1.1 install.lunar, NONE, 1.1 main.lunar, NONE, 1.1 misc.lunar, NONE, 1.1 prune.lunar, NONE, 1.1 temp.lunar, NONE, 1.1 tracking.lunar, NONE, 1.1

csm at lunar-linux.org csm at lunar-linux.org
Sun Aug 10 01:18:57 GMT 2003


Update of /var/cvs/lunar/lunar/var/lib/lunar/functions
In directory dbguin.lunar-linux.org:/tmp/cvs-serv2035/var/lib/lunar/functions

Added Files:
	build.lunar check.lunar connect.lunar init.lunar install.lunar 
	main.lunar misc.lunar prune.lunar temp.lunar tracking.lunar 
Log Message:
these are the adds to complete the merge


--- NEW FILE: build.lunar ---
#!/bin/bash
#                                                          #
# subroutines - Lunar subroutines                          #
#                                                          #
############################################################
#                                                          #
# this WAS the subroutines 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Copyright 2001 by Kyle Sallee                            #
#                                                          #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2        #
#                                                          #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################


save_libraries()  {
  debug_msg "save_libraries ($@)"

  [ "$MODULE" == "glibc" ] && return 0

  OLD_VERSION=`installed_version  $MODULE`
  OLD_LOG=$INSTALL_LOGS/$MODULE-$OLD_VERSION

  [ -e "$OLD_LOG" ] || return 0      

  OLD_LIBS=$SOURCE_DIRECTORY/old.libraries
  mkdir  -p  $OLD_LIBS

  SAVED=$OLD_LIBS/$MODULE.saved.libraries
  rm  -rf  $SAVED

  grep   "/lib/"  $OLD_LOG  |
  while  read  LINE;  do

    if [ -f "$LINE"  ]  &&
         file  -bL  $LINE   |
         grep  -q   "shared object"
    then
      verbose_msg "saving library \"$LINE\""
      if  [  -h  $LINE  ];  then
        DEST=$(  basename  $(  ls   -la  "$LINE"  |
                               cut  -d  '>'  -f2  |
                               cut  -c  2-
                            )
              )
        ln  -sf  $DEST  $OLD_LIBS/`basename  $LINE`
      else
        cp  $LINE  $OLD_LIBS
      fi
      echo  $OLD_LIBS/`basename  $LINE`  >>  $SAVED
    fi
  done

  ldconfig  $OLD_LIBS

  if  [  -z   "$LD_LIBRARY_PATH"  ]
  then  export  LD_LIBRARY_PATH="$OLD_LIBS"
  else  export  LD_LIBRARY_PATH="$OLD_LIBS:$LD_LIBRARY_PATH"
  fi
}


release_saved_libraries()  {
  debug_msg "release_saved_libraries ($@)"
   OLD_LIBS=$SOURCE_DIRECTORY/old.libraries
   SAVED=$OLD_LIBS/$MODULE.saved.libraries

   [  -f  $SAVED  ]    &&
   cat    $SAVED       |
   while  read  FILE;  do
     verbose_msg "releasing library \"$FILE\""
     rm  -f   "$FILE"
   done

   ldconfig  $OLD_LIBS
}


prepare_install() {
  debug_msg "prepare_install ($@)"
  if  module_installed $MODULE  || module_held $MODULE ; then
    message  "${MESSAGE_COLOR}Preparing to install"  \
             "${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"

    while  boost_locked;  do
      sleep  5
    done

    echo  $$  >  $BOOST_LOCK

    save_libraries
    verbose_msg "calling \"lrm --keepconfig --nosustain $MODULE\""
    lrm  --keepconfig  --nosustain  $MODULE
    true
  fi
}


rm_source_dir() {
  debug_msg "rm_source_dir ($@)"

  [ "$KEEP_SOURCE" == "on" ] && return 0

  cd  $BUILD_DIRECTORY

  DEAD_DIR=$1
  DEAD_DIR=${DEAD_DIR:=$SOURCE_DIRECTORY}

  verbose_msg "destroying building dir \"$DEAD_DIR\""

  if [ "$TMPFS" != "off" ]; then
    umount     $DEAD_DIR  2>  /dev/null
    rmdir      $DEAD_DIR  2>  /dev/null
  else
    rm   -rf   $DEAD_DIR  2>  /dev/null
  fi

  rm     -f  $BOOST_LOCK

}


mk_source_dir() {
  debug_msg "mk_source_dir ($@)"

  cd  $BUILD_DIRECTORY

  NEW_DIR=$1
  NEW_DIR=${NEW_DIR:=$SOURCE_DIRECTORY}

  verbose_msg "creating building dir \"$NEW_DIR\""

  if [ "$TMPFS" != "off" ]; then 
    umount  $NEW_DIR  2>/dev/null
    rmdir   $NEW_DIR  2>/dev/null
    mkdir  -p  $NEW_DIR  &&
    mount  -o  size=1g,nr_inodes=1m  -t  tmpfs  tmpfs  $NEW_DIR
  else
    rm -rf  $NEW_DIR  2>/dev/null
    mkdir  -p  $NEW_DIR
  fi

}


validate_source_dir()  {
  debug_msg "validate_source_dir ($@)"

  verbose_msg "validating \"$SOURCE_DIRECTORY\""
  if  [  -n    "$SOURCE_DIRECTORY"                                   ]  &&
      [        "$SOURCE_DIRECTORY"  !=           "$BUILD_DIRECTORY"  ]  &&
      echo     "$SOURCE_DIRECTORY"  |  grep  -q  "$BUILD_DIRECTORY"
  then
    true
  else
    message  "\$SOURCE_DIRECTORY and \$BUILD_DIRECTORY must not be the same."
    message  "\$SOURCE_DIRECTORY must not be empty."
    message  "\$SOURCE_DIRECTORY must be a subdirectory of \$BUILD_DIRECTORY"
    false
  fi

}


default_pre_build() {
  debug_msg "default_pre_build ($@)"
  verbose_msg "running \"default_pre_build\""
  validate_source_dir  $SOURCE_DIRECTORY 
  if [[ -d $SOURCE_DIRECTORY ]] &&
     [[ $KEEP_SOURCE == "on" ]]; then
    cd $SOURCE_DIRECTORY && 
    make clean
  else
    mk_source_dir        $SOURCE_DIRECTORY &&
    unpack               $SOURCE
  fi
}


default_config() {
  debug_msg "default_config ($@)"
  verbose_msg "running \"default_config\""

  verbose_msg "CFLAGS=\"$CFLAGS\""            &&
  verbose_msg "OPTS=\"$OPTS\""                &&
  verbose_msg "./configure --build=$BUILD --prefix=/usr --sysconfdir=/etc --localstatedir=/var --infodir=/usr/share/info --mandir=/usr/share/man $OPTS"

  ./configure  --build=$BUILD            \
               --prefix=/usr             \
               --sysconfdir=/etc         \
               --localstatedir=/var      \
               --infodir=/usr/share/info \
               --mandir=/usr/share/man   \
               $OPTS
} > $C_FIFO 2>&1


default_cvs_config() {
  debug_msg "default_cvs_config ($@)"
  verbose_msg "running \"default_cvs_config\""

  verbose_msg "CFLAGS=\"$CFLAGS\""            &&
  verbose_msg "OPTS=\"$OPTS\""                &&
  verbose_msg "./autogen.sh --build=$BUILD --prefix=/usr --sysconfdir=/etc --localstatedir=/var --infodir=/usr/share/info --mandir=/usr/share/man $OPTS"

  ./autogen.sh --build=$BUILD            \
               --prefix=/usr             \
               --sysconfdir=/etc         \
               --localstatedir=/var      \
               --infodir=/usr/share/info \
               --mandir=/usr/share/man   \
               $OPTS
} > $C_FIFO 2>&1


default_make() {
  debug_msg "default_make ($@)"
  verbose_msg "running \"default_make\""
  make                               &&
  prepare_install                    &&
  make    install
} > $C_FIFO 2>&1


default_build() {
  debug_msg "default_build ($@)"
  verbose_msg "running \"default_build\""
  default_config  &&
  default_make
} > $C_FIFO 2>&1


default_cvs_build() {
  debug_msg "default_cvs_build ($@)"
  verbose_msg "running \"default_cvs_build\""
  default_cvs_config  &&
  default_make
} > $C_FIFO 2>&1


default_post_build() {
  debug_msg "default_post_build ($@)"
  {
    gather_docs

    install_pam_confs
    install_services
    install_xinetd_confs
    install_initd
    install_bashmisc
  } | tee -a $C_LOG

  devoke_installwatch
  ldconfig
  release_saved_libraries
  cd  /
}


# function : remove_module
# usage    : remove_module; but $MODULE must be defined earlier
# purpose  : removed a module from the MODULE_STATUS files, no source removal
remove_module() {
  debug_msg "remove_module ($@)"

  verbose_msg "updating lunar state files after module removal"
  lock_file $MODULE_STATUS                                     && 
  lock_file $MODULE_STATUS_BACKUP                              &&
  grep  -v  "^$1:" $MODULE_STATUS_BACKUP  >  $MODULE_STATUS 2>/dev/null
  cat $MODULE_STATUS >  $MODULE_STATUS_BACKUP               2>/dev/null
  unlock_file $MODULE_STATUS_BACKUP                            &&
  unlock_file $MODULE_STATUS 

  if [ -n "$EXILE" ] ; then
     lock_file $MODULE_STATUS                            && 
     lock_file $MODULE_STATUS_BACKUP                     &&
     echo  "$1::exiled:0.0"  >>  $MODULE_STATUS          &&
     cat  $MODULE_STATUS      >  $MODULE_STATUS_BACKUP   &&
     unlock_file $MODULE_STATUS_BACKUP                   &&
     unlock_file $MODULE_STATUS 

     lock_file $DEPENDS_STATUS                           &&
     lock_file $DEPENDS_STATUS_BACKUP                    &&
     grep  -v  ":$1:" $DEPENDS_STATUS_BACKUP  >   $DEPENDS_STATUS  &&
     cat $DEPENDS_STATUS >  $DEPENDS_STATUS_BACKUP       &&
     unlock_file $DEPENDS_STATUS                         &&
     unlock_file $DEPENDS_STATUS_BACKUP
  fi
}


# function: add_module
# usage   : add_module <module_name>
# purpose : adds the 1st parameter as the module name to the MODULE_STATUS files
add_module()  {
  debug_msg "add_module ($@)"
  verbose_msg "updating lunar state files after module installation"
  lock_file $MODULE_STATUS                                    && 
  lock_file $MODULE_STATUS_BACKUP                             &&
  grep  -v  "^$1:" $MODULE_STATUS_BACKUP   >   $MODULE_STATUS 2>/dev/null  &&
  echo  "$1:`date  -u  +%Y%m%d`:$2:$3:$4"  >>  $MODULE_STATUS &&
  cat  $MODULE_STATUS      >  $MODULE_STATUS_BACKUP           &&
  unlock_file $MODULE_STATUS_BACKUP                           &&
  unlock_file $MODULE_STATUS 
}


push_install_queue() {
  debug_msg "push_install_queue ($@)"
  remove_queue   $REMOVE_QUEUE    "$1"
  remove_queue   $INSTALL_QUEUE   "$1"
  !  module_installed             "$1"  &&
  add_queue  $INSTALL_QUEUE       "$1"
}


push_remove_queue() {
  debug_msg "push_remove_queue ($@)"

  remove_queue   $INSTALL_QUEUE  "$1"
  remove_queue   $REMOVE_QUEUE   "$1"
  module_installed               "$1"  &&
  add_queue  $REMOVE_QUEUE       "$1"
}


# function : sort_install_queue
# usage    : sort_install_queue
# purpose  : sorts the install queue according to the dependencies
sort_install_queue() {
  debug_msg "sort_install_queue ($@)"
   for MODULE in $@; do
     QUEUE="$QUEUE $MODULE"
     show_fancy_progress "Processing: $MODULE"
     for DEP in $(find_depends $MODULE) ; do
       if $(echo "$@" | grep -qw "$DEP") ; then
         QUEUE="$DEP $QUEUE"
       fi
     done
   done

   echo $QUEUE | tsort
}


# function : purge_modules
# usage    : purge_modules
# purpose  : purge modules that were removed from moonbase
purge_modules() {
  debug_msg "purge_modules ($@)"
  verbose_msg "Discovering modules that were removed from moonbase"
  for MODULE in $(list_installed | grep -v "^moonbase$") ; do
  (
    if ! run_details $MODULE &> /dev/null ; then
      message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} was removed from ${FILE_COLOR}${MOONBASE}${DEFAULT_COLOR}"
      if query "Do you want to remove ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${QUERY_COLOR} ?" y ; then
        lrm $MODULE
        continue
      else
        message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} is kept and can be removed manually later${DEFAULT_COLOR}"
      fi
    fi
  )
  done 
}


# function : list_expired_modules
# usage    : list_expired_modules
# purpose  : return a list of modules that need to be updated
list_expired_modules() {
  debug_msg "list_expired_modules ($@)"
  for LINE in $(cat $MODULE_STATUS | grep -v "^moonbase" | sort) ; do
  (
    MODULE=$(echo "$LINE" | cut -d: -f1)
    IDATE=$(echo "$LINE" | cut -d: -f2)
    STATUS=$(echo "$LINE" | cut -d: -f3)
    IVERSION=$(echo "$LINE" | cut -d: -f4)
    if run_details $MODULE &> /dev/null ; then
      if [ "$STATUS" == "installed" ] ; then
        if [ "$VERSION" != "$IVERSION" ] || [ -z "$IDATE" ] || 
          (( "$UPDATED" > "$IDATE" )) ; then
          if [ "$MODULE" != "lunar" ] && [ "$MODULE" != "theedge" ] ; then
            echo $MODULE
          fi
	fi
      fi
    fi
  )
  done
}


# function : sort_by_dependency
# usage    : LIST=$(sort_by_dependency $LIST)
# purpose  : return a LIST sorted by dependency
sort_by_dependency() {
  debug_msg "sort_by_dependency ($@)"
  LIST=$@
  for MODULE in $LIST ; do
    unset DEPS
    for DEP in $(find_depends $MODULE) ; do
      if $(echo $LIST | grep -qw $DEP) ; then
        DEPS="$DEPS $DEP"
      fi
    done
    TMP_LIST="$TMP_LIST $DEPS $MODULE"
  done
  
  for MODULE in $TMP_LIST ; do
    if ! $(echo $QUEUE | grep -qw $MODULE) ; then
      QUEUE="$QUEUE $MODULE"
    fi
  done

  echo $QUEUE
}


# function : update_modules
# usage    : update_modules
# purpose  : update all installed modules that need to be updated
update_modules() {
  debug_msg "update_modules ($@)"

  export IFS="$STANDARD_IFS"

  verbose_msg "Searching for modules to update"
  LIST=$(list_expired_modules)
  
  if [ -z "$LIST" ] ; then
    verbose_msg "Nothing to update!"
    return
  fi
  
  verbose_msg "Sorting update queue"
  QUEUE=$(sort_by_dependency $LIST)

  message "${MESSAGE_COLOR}The following modules will be updated:${DEFAULT_COLOR}"
  TMP_QUEUE=$(temp_create "update-queue")
  for MODULE in $QUEUE ; do
    echo $MODULE >> $TMP_QUEUE
    echo $MODULE
  done

  unset MODULE
  if query "Do you wish to edit the update queue ? " n ; then
    edit_file $TMP_QUEUE
  fi
  QUEUE=$(cat $TMP_QUEUE)
  temp_destroy $TMP_QUEUE

  if [ -n "$QUEUE" ] ; then
    lin -c $QUEUE
  fi
}



log_list()  {
  debug_msg "log_list ($@)"

   echo `cat  $MODULE_STATUS_BACKUP                | \
         cut  -d  :  -f1,4 --output-delimiter="-"`

}


clean_logs()  {
  debug_msg "clean_logs ($@)"

  LOGS=`log_list`

  for  FILE  in  `ls  $INSTALL_LOGS`;  do
    if  !  echo  -e  "$LOGS"  |  grep  -q  $FILE;  then
      message  "Removing stale log  :  $INSTALL_LOGS/$FILE"
      rm                               $INSTALL_LOGS/$FILE
    fi
  done

  for  FILE  in  `ls  $COMPILE_LOGS | sed  "s/\.bz2//"`;  do
    if  !  echo  -e  "$LOGS"  |  grep  -q  $FILE;  then
      message  "Removing stale log  :  $COMPILE_LOGS/$FILE.bz2"
      rm                               $COMPILE_LOGS/$FILE.bz2
    fi
  done

  for  FILE  in  `ls  $MD5SUM_LOGS`;  do
    if  !  echo  -e  "$LOGS"  |  grep  -q  $FILE;  then
      message  "Removing stale log  :  $MD5SUM_LOGS/$FILE"
      rm                               $MD5SUM_LOGS/$FILE
    fi
  done

}

activity_log()  {
  debug_msg "activity_log ($@)"

    DATE=`date  -u  +%Y%m%d-%T`
  COMMAND=$1
   MODULE=$2
  VERSION=$3
  OUTCOME=$4
     INFO=$5

  lock_file $ACTIVITY_LOG &&
  echo "$DATE	$COMMAND	$MODULE	$VERSION	$OUTCOME	$INFO"  >> $ACTIVITY_LOG &&
  unlock_file $ACTIVITY_LOG
}


syms_not_owned()  {
  debug_msg "syms_not_owned ($@)"

  cat  $1  |
  while read ITEM ; do

    if  [  -h  "$ITEM"  ]   &&
        [  -f  "$ITEM"  ];  then

      DEST=$(  basename  $(  ls   -la  "$ITEM"  |
                             cut  -d  '>'  -f2  |
                             cut  -c  2-
                          )
            )

      if  !  grep  -q  "$DEST"  "$1"
      then   echo  -n  "$ITEM\|"
             echo      "$ITEM"  >>  /tmp/$MODULE.rejected.symlinks
      fi

    fi

  done

}


find_pam_aware()  {
  debug_msg "find_pam_aware ($@)"

  cat  $MODULE_STATUS_BACKUP  |
  while  read  LINE;  do
                        
    MODULE="`echo  $LINE  |  cut  -d  :  -f1`"
    STATUS="`echo  $LINE  |  cut  -d  :  -f3`"
                                              
    if  [  "$STATUS"  ==  "installed"  ]   ||
        [  "$STATUS"  ==  "held"       ];  then

      SECTION=`find_section  $MODULE`
                                    
      if    [  -d  "$MOONBASE/$SECTION/$MODULE/pam.d"  ]  &&
            [  "$MODULE"  !=  "Linux-PAM"              ]
      then  echo  $MODULE
      fi

    fi
  done

}



--- NEW FILE: check.lunar ---
#!/bin/bash
#                                                          #
# check/lunar - checking functions                         #
#                                                          #
############################################################
# cast is part of the sorcery spell management utility     #
# Copyright 2001 by Kyle Sallee                            #
############################################################
#                                                          #
# this WAS the cast 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Parts Copyrighted Jason Johnston  2002 under GPLv2       #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################


ldd_check()  {
  debug_msg "ldd_check ($@)"
  if  [  "$LDD_CHECK"  ==  "off"    ] ;  then
    return
  fi
     MODULE=$1
     VERSION=`installed_version  $MODULE`
       I_LOG=$INSTALL_LOGS/$MODULE-$VERSION
  LDD_STATUS=0

  if  [  -e  "$I_LOG"  ];  then
    IFS_OLD="$IFS"
    export  IFS="	
"

    LOG=`cat   $I_LOG                               |
         grep      "/bin/\|/games/\|/lib/\|/sbin/"  |
         grep  -v  "/doc/\|/fonts/\|/include/\|/locale/\|/man/\|/modules/\|/var/"`

    for  FILE  in  $LOG;  do
      if  [     -f  "$FILE"  ]     &&
          [  !  -h  "$FILE"  ]     &&
          file  -b  "$FILE"        |
          grep  -q  "ELF"          &&
          ldd       "$FILE"  2>&1  |
          grep  -q  "not found"
      then
        (  export  IFS="$IFS_OLD"
           message  "${FILE_COLOR}${FILE}"        \
                    "${DEFAULT_COLOR}of"          \
                    "${MODULE_COLOR}${MODULE}"    \
                    "${PROBLEM_COLOR}is broken."  \
                    "${DEFAULT_COLOR}"
           ldd      "$FILE" 2>&1 | grep  "not found"
        )
        LDD_STATUS=1
      fi
    done
  fi
  return  $LDD_STATUS
}


find_check()  {
  debug_msg "find_check ($@)"
  if  [  "$FIND_CHECK"  ==  "off"             ]   ||
      [  "$1"           ==  "xfree86"         ]   ||
      [  "$1"           ==  "xfree86-custom"  ];  then
    return
  fi
      MODULE=$1
      VERSION=`installed_version  $MODULE`
        I_LOG=$INSTALL_LOGS/$MODULE-$VERSION
  FIND_STATUS=0

  if  [  -e  "$I_LOG"  ];  then
    IFS_OLD="$IFS"
    export  IFS="	
"

    LOG=`cat   $I_LOG                                          |
         grep      "/bin/\|/games/\|/include/\|/lib/\|/sbin/"  |
         grep  -v  "/doc/\|/etc/\|/fonts/\|/man/\|/var/"`

    for ITEM in $LOG ; do
      if  [  -e  "$ITEM"  ];  then
        true
      else
        (  export  IFS="$IFS_OLD"
           message  "${FILE_COLOR}${ITEM}"         \
                    "${DEFAULT_COLOR}of"           \
                    "${MODULE_COLOR}${MODULE}"       \
                    "${PROBLEM_COLOR}is missing."  \
                    "${DEFAULT_COLOR}"
        )
        FIND_STATUS=1
      fi
    done
  else
    (  export  IFS="$IFS_OLD"
       message  "${MODULE_COLOR}${MODULE} "                     \
                "${PROBLEM_COLOR}is missing an install log."  \
                "${DEFAULT_COLOR}"
    )
    FIND_STATUS=1
  fi
  return  $FIND_STATUS
}


sym_check()  {
  debug_msg "sym_check ($@)"
  if  [  "$SYM_CHECK"  ==  "off"  ];  then
    return
  fi
      MODULE=$1
	  VERSION=`installed_version  $MODULE`
        I_LOG=$INSTALL_LOGS/$MODULE-$VERSION

  if  [  -e  "$I_LOG"  ];  then
    IFS_OLD="$IFS"
    export  IFS="	
"

    LOG=`cat   $I_LOG`

    for ITEM in $LOG ; do
      if  [  -h  "$ITEM"  ]  &&
          [  -f  "$ITEM"  ]
      then
      TARGET=$(  basename  $(  ls   -la  "$ITEM"  |
                               cut  -d  '>'  -f2  |
                               cut  -c  2-
                            )
              )
        if  !  grep  -q  "$TARGET"  $I_LOG
        then  (  export  IFS="$IFS_OLD";  remove_line  )
        fi
      fi
    done
  fi
}


md5sum_check()  {
  debug_msg "md5sum_check ($@)"
  if  [  "$MD5SUM_CHECK"  ==  "off"  ];  then
    return
  fi

  MODULE=$1
  VERSION=`installed_version  $MODULE`
  MD5_LOG="$MD5SUM_LOGS/$MODULE-$VERSION"

  MD5SUM_STATUS=0

  if  [  -e  "$MD5_LOG"  ];  then
    IFS_OLD="$IFS"
    export  IFS="	
"

    OUTPUT=`cat  $MD5_LOG                                         |
            grep      "/bin/\|/games/\|/include/\|/lib/\|/sbin/"  |
            grep  -v  "/doc/\|/etc/\|/fonts/\|/man/\|/var/"       |
            md5sum  --check  2>/dev/null                          |    
            grep   -v       ": OK"                                |
            cut    -d :  -f1`

    if  [  -n  "$OUTPUT"  ];  then
      for  FILE  in  $OUTPUT;  do
        if  [     -f  "$FILE"  ]  &&
            [  !  -h  "$FILE"  ]  &&
            file  -b  "$FILE"     |
            egrep  -q  "executable|shared object|current ar archive"
        then
          MD5SUM=`md5sum  $FILE`
          if  !  grep  -q  "$MD5SUM"  $MD5SUM_LOGS/*;  then
            (  export  IFS="$IFS_OLD"
               message  "${FILE_COLOR}${FILE}"               \
                        "${DEFAULT_COLOR}of"                 \
                        "${MODULE_COLOR}${MODULE}"           \
                        "${PROBLEM_COLOR}has wrong md5sum."  \
                        "${DEFAULT_COLOR}"
            )
            MD5SUM_STATUS=1
          fi
        fi
      done
    fi
  else
    (  export  IFS="$IFS_OLD"  
       message  "${MODULE_COLOR}${MODULE} "                 \
                "${PROBLEM_COLOR}is missing a md5sum log."  \
                "${DEFAULT_COLOR}"
    )
    MD5SUM_STATUS=1
  fi
  return  $MD5SUM_STATUS
}


run_checks() {
  debug_msg "run_checks ($@)"
  sym_check    $1
  find_check   $1 &&
  ldd_check    $1 &&
  md5sum_check $1
}


# rework_module : check depends database for a module
rework_module() {
  debug_msg "rework_module ($@)"
                                                                                
  # we declare these local to override the systems default ones:
  optional_depends()  {
  debug_msg "  optional_depends ($@)"
    if    module_exiled  $1
    then  add_depends  "$MODULE"  "$1"  "off"  "optional"  "$2"  "$3"
    else
      if  module_installed  $1  ||
          module_held       $1
      then  add_depends  "$MODULE"  "$1"  "on"   "optional"  "$2"  "$3"
      else  add_depends  "$MODULE"  "$1"  "off"  "optional"  "$2"  "$3"
      fi
    fi
  }
                                                                                
  depends()  {
  debug_msg "  depends ($@)"
    if  ! module_installed  $1   &&
        ! module_held       $1
    then
      if  !  is_depends     $1   &&
             module_exiled  $1
      then  return  1
      else
        echo -e "${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}${MESSAGE_COLOR} is missing ${MODULE_COLOR}$1${DEFAULT_COLOR}"
        CHANGED_MODULES="$CHANGED_MODULES $1"
      fi
    fi
    add_depends  "$MODULE"  "$1"  "on"  "required"  "$2"  "$3"
  }
  run_depends() {
  debug_msg "  run_depends ($@)"
    if [ -s "$SCRIPT_DIRECTORY/DEPENDS" ] ; then
      show_fancy_progress "Processing: $MODULE"
      run_module_file $MODULE DEPENDS
    fi
  }
                                                                                
  # here starts the real work:
  MODULE=$1
                                                                                
  # base vars needed to execute DEPENDS
  SECTION=$(find_section $MODULE)
  SCRIPT_DIRECTORY=$MOONBASE/$SECTION/$MODULE
  MODULE_CONFIG=$DEPENDS_CONFIG/$MODULE
                                                                                
  # reroute depends output to our private files:
  OLD_DEPENDS_STATUS=$DEPENDS_STATUS
  OLD_DEPENDS_STATUS_BACKUP=$DEPENDS_STATUS_BACKUP
                                                                                
  DEPENDS_STATUS=$TMP/depends
  DEPENDS_STATUS_BACKUP=$TMP/depends.backup
  touch $DEPENDS_STATUS
  touch $DEPENDS_STATUS_BACKUP
                                                                                
  # fetch old depend data:
  grep "^$MODULE:" $OLD_DEPENDS_STATUS | sort | uniq > $TMP/depends.old.$MODULE
                                                                                
  # fetch new depend data:
  run_depends
  grep "^$MODULE:" $DEPENDS_STATUS | sort | uniq > $TMP/depends.new.$MODULE
                                                                                
  if $(! diff -q $TMP/depends.old.$MODULE $TMP/depends.new.$MODULE &> /dev/null
) ; then
    echo -e "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} has changed depends:${DEFAULT_COLOR}"
    CHANGED_MODULES="$CHANGED_MODULES $MODULE"
    LIST=$(cat $TMP/depends.old.$MODULE $TMP/depends.new.$MODULE | cut -d: -f2 | sort | uniq )
    for DEP in $LIST; do
      OLDDEP=$(grep ":$DEP:" $TMP/depends.old.$MODULE)
      NEWDEP=$(grep ":$DEP:" $TMP/depends.new.$MODULE)
      if [ "$OLDDEP" != "$NEWDEP" ] ; then
                                                                                
        # diff style output for debugging:
        # echo "- $OLDDEP"
        # echo "+ $NEWDEP"
                                                                                
        # the tricky part is deciding what is necessary and what not:
        OLD_STATUS=$(echo $OLDDEP | cut -d: -f3)
        NEW_STATUS=$(echo $NEWDEP | cut -d: -f3)
        OLD_REQD=$(echo $OLDDEP | cut -d: -f4)
        NEW_REQD=$(echo $NEWDEP | cut -d: -f4)
        OLD_ON_OPTS=$(echo $OLDDEP | cut -d: -f5)
        NEW_ON_OPTS=$(echo $NEWDEP | cut -d: -f5)
        OLD_OFF_OPTS=$(echo $OLDDEP | cut -d: -f6)
        NEW_OFF_OPTS=$(echo $NEWDEP | cut -d: -f6)
        if [ -z "$NEWDEP" ] ; then
          echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was removed from the dependency list${DEFAULT_COLOR}"
        else
          if [ -z "$OLDDEP" ] ; then
            echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was added to the $NEW_REQD dependency list${DEFAULT_COLOR}"
          else
            # the dep changed!
            if [ "$OLD_STATUS" == "on" -a "$NEW_STATUS" == "on" ]; then
              if [ "$OLD_REQD" == "required" -a "$NEW_REQD" == "optional" ]
              then
                echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to optional${DEFAULT_COLOR}"
              elif [ "$OLD_REQD" == "optional" -a "$NEW_REQD" == "required" ]
              then
                echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to required${DEFAULT_COLOR}"
              else
                echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} has new compile flags for ${MODULE_COLOR}$DEP${MESSAGE_COLOR}${DEFAULT_COLOR}"
              fi
            elif [ "$OLD_STATUS" == "off" -a "$NEW_STATUS" == "off" ]; then
              if [ "$OLD_REQD" == "required" -a "$NEW_REQD" == "optional" ]
              then
                echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to optional${DEFAULT_COLOR}"
              elif [ "$OLD_REQD" == "optional" -a "$NEW_REQD" == "required" ]
              then
                echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to required${DEFAULT_COLOR}"
              else
                echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} has new compile flags for ${MODULE_COLOR}$DEP${MESSAGE_COLOR}${DEFAULT_COLOR}"
              fi
            elif [ "$OLD_STATUS" == "off" -a "$NEW_STATUS" == "on" ]; then
              echo -e "${MESSAGE_COLOR}* $NEW_REQD ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was installed${DEFAULT_COLOR}"
            elif [ "$OLD_STATUS" == "on" -a "$NEW_STATUS" == "off" ]; then
              echo -e "${MESSAGE_COLOR}* $NEW_REQD ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was removed${DEFAULT_COLOR}"
            else
              echo -e "${$MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} ${PROBLEM_COLOR}missed exception $OLD_STATUS $NEW_STATUS${DEFAULT_COLOR}"
            fi
          fi
        fi
      fi
    done
  fi
                                                                                
  # clean up
  rm -f $DEPENDS_STATUS
  rm -f $DEPENDS_STATUS_BACKUP
  DEPENDS_STATUS=$OLD_DEPENDS_STATUS
  DEPENDS_STATUS_BACKUP=$OLD_DEPENDS_STATUS_BACKUP
                                                                                
}


# rework_list : rework a list of modules and save output
rework_list() {
  debug_msg "rework_list ($@)"
                                                                                
  for MODULE in $* ; do
    module_exiled $MODULE || rework_module $MODULE
  done
                                                                                
}
                                                                                

# fix_depends : single pass to fix depends database
fix_depends () {
  debug_msg "fix_depends  ($@)"
                                                                                
  TMP=/tmp/lunar.fix
  [ -d $TMP ] || mkdir -p $TMP
                                                                                
  CHANGED_MODULES=
  # we NEED this
  if [ -f "$INSTALL_QUEUE" ] ; then
    rm -f $INSTALL_QUEUE
    touch $INSTALL_QUEUE
  fi
                                                                                
  if [ -n "$1" ] ; then
    rework_list $*
  else
    rework_list $(cat $MODULE_STATUS | cut -d: -f1 | sort )
  fi
                                                                                
  if [ -n "$CHANGED_MODULES" ] ; then
                                                                                
    for MODULE in $CHANGED_MODULES ; do
      if [ ! -e "$TMP/depends.new.$MODULE" ] ; then
        rework_module $MODULE
      fi
    done
                                                                                
    # this ensures the bastard doesn't recheck it:
    if [ -z "$NOFIX" ] ; then
      mv $DEPENDS_STATUS $TMP/depends
      cp $TMP/depends $TMP/depends.filter
      for MODULE in $CHANGED_MODULES ; do
        grep -v "^$MODULE:" $TMP/depends.filter > $TMP/depends.filter~
        mv $TMP/depends.filter~ $TMP/depends.filter
      done
      mv $TMP/depends.filter $DEPENDS_STATUS
      cat $TMP/depends.new.* >> $DEPENDS_STATUS
      cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
    fi
                                                                                
    OLD_FIX=$FIX
    unset FIX
    OLD_lin_PASS=$lin_PASS; export lin_PASS=three
                                                                                
    for MODULE in $CHANGED_MODULES ; do
      if [ -n "$FIXDEPENDS" ] ; then
        # special case: when called with --fixdepends, skip recompile!
        cp $TMP/depends $TMP/depends.filter
        for MODULE in $CHANGED_MODULES ; do
          grep -v "^$MODULE:" $TMP/depends.filter > $TMP/depends.filter~
          mv $TMP/depends.filter~ $TMP/depends.filter
        done
        mv $TMP/depends.filter $DEPENDS_STATUS
        cat $TMP/depends.new.* >> $DEPENDS_STATUS
        cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
      else
        if [ -z "$NOFIX" ] ; then
          if ! lin -c $MODULE ; then
            # put back the faulty depends so we know fixing this failed
            # and will be found again on the next run
            cat $TMP/depends > $DEPENDS_STATUS
            cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
          else
            # sometimes after lin all depends are gone! force it down it's throat
            cp $TMP/depends $TMP/depends.filter
            for MODULE in $CHANGED_MODULES ; do
              grep -v "^$MODULE:" $TMP/depends.filter > $TMP/depends.filter~
              mv $TMP/depends.filter~ $TMP/depends.filter
            done
            mv $TMP/depends.filter $DEPENDS_STATUS
            cat $TMP/depends.new.* >> $DEPENDS_STATUS
            cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
          fi
        fi
      fi
      remove_queue $INSTALL_QUEUE $MODULE
    done
                                                                                
    FIX=$OLD_FIX
    unset OLD_FIX
    export lin_PASS=$OLD_lin_PASS
                                                                                
  fi
                                                                                
  rm -rf $TMP
                                                                                
}
                                                                                

run_fix()  {
  debug_msg "run_fix ($@)"
  MODULES=$*

  if [ -z "$MODULES" ] ; then
    MODULES=$(cat $MODULE_STATUS_BACKUP | cut  -d: -f1 | sort)
  fi

  PASSED=":"

  verbose_msg "Saving LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\""
  [ -n "$EXPORT_LD_PATH" ] ||
    export EXPORT_LD_PATH=$(find /usr/lib -type d ! -empty)
  if  [  "$LDD_CHECK"  ==  "on"    ] ;  then
    LD_LIBRARY_PATH_OLD="$LD_LIBRARY_PATH"
    export_ld $EXPORT_LD_PATH
  fi

  until  [  "$FIXED"     ==  "yes"  ]   ||
         [  "$HOPELESS"  ==  "yes"  ];  do

       FIXED="yes"
    HOPELESS="no"

    for  MODULE  in  $MODULES;  do

      fix_depends $MODULE

      # if we were called with --fixdepends then we may skip the rest
      if [ -n "$FIXDEPENDS" ] ; then
        continue
      fi        

      if module_installed $MODULE                      &&
          [  "$MODULE"  !=  "lunar"  ]                 &&
          [  "$MODULE"  !=  "j2sdk"    ]               &&
	  module_held $MODULE                          &&
          !  echo  $PASSED  |  grep  -q  ":$MODULE:";  then

        if    run_checks     $MODULE  ||
              [  -n  "$NOFIX"  ]
        then
          PASSED="$PASSED$MODULE:"
        else
          FIXED="no"
          (  
	    run_details $MODULE  &&
            satisfy_depends      &&
            unset FIX            &&
            satisfy_depends
          )

          if  [  "$LDD_CHECK"  ==  "on"    ] ;  then
            export  LD_LIBRARY_PATH="$LD_LIBRARY_PATH_OLD"
            export_ld $EXPORT_LD_PATH
          fi

          if    run_checks     $MODULE  ||
                [  -n  "$NOFIX"  ]
          then

            PASSED="$PASSED$MODULE:"
            if  [  "$LDD_CHECK"  ==  "on"    ] ;  then
              export  LD_LIBRARY_PATH="$LD_LIBRARY_PATH_OLD"
              export_ld $EXPORT_LD_PATH 
            fi

          else
            unset  FIX
            if    !  lin  --compile  $MODULE;  then  HOPELESS="yes"
            elif  !  run_checks      $MODULE;  then  HOPELESS="yes"
            fi
            export  FIX="--fix"
          fi
        fi
      fi
    done
  done
  rm  -f  /tmp/LD_LIBRARY_PATH_FILE
}




--- NEW FILE: connect.lunar ---
#!/bin/bash
############################################################
#                                                          #
# download.lunar - get sources from the net                #
#                                                          #
############################################################
# leach is part of the sorcery spell management utility    #
# Copyright 2001 by Kyle Sallee                            #
############################################################
#                                                          #
# this WAS the leach 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
# This secondly was lget mostly, and has been moved into   #
# a separate lunar functions file handling all the generic #
# downloading functionality for lunar                      #
#                                                          #
############################################################
#                                                          #
# Parts Copyrighted  Jason Johnston  2002 under GPLv2      #
#                                                          #
# Parts Copyrighted  Kagan Kongar  2002 under GPLv2        #
#                                                          #
# Parts Copyrighted  Auke Kok  2002 under GPLv2            #
#                                                          #
############################################################


connect()  {
  debug_msg "connect ($@)"

  if  !  ifconfig  |  grep  -q  "^eth"   &&
      !  ifconfig  |  grep  -q  "^wlan"  &&
      !  ifconfig  |  grep  -q  "^ppp"   &&
      !  ifconfig  |  grep  -q  "^tun";  then
    pon

    # Timeout in deciseconds to wait for Interface to come up.
    TIMEOUT=30

    until  ifconfig  |  grep  -q  eth   ||
           ifconfig  |  grep  -q  ppp   ||
           [  $TIMEOUT == 0  ]
    do
      sleep  10
      (( TIMEOUT-- ))
    done
    disconnect

  fi

}


disconnect()  {
  debug_msg "disconnect ($@)"
  if    ps  -C disconnect  >  /dev/null
  then  return
  fi

  rm  -f           /tmp/disconnect
  cat  <<  EOF  >  /tmp/disconnect
#!/bin/sh

while  ps  -A  |  grep  -q  "lget";  do  sleep  120;  done
poff
rm  -f  /tmp/disconnect
EOF

chmod  a+x  /tmp/disconnect
            /tmp/disconnect  &

}



--- NEW FILE: init.lunar ---
#!/bin/bash
#                                                          #
# init.lunar - Lunar subroutines                           #
#                                                          #
############################################################
#                                                          #
# this WAS the subroutines 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Copyright 2001 by Kyle Sallee                            #
#                                                          #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2        #
#                                                          #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################


# function : enviro_check
# usage    : enviro_check
# purpose  : check if the shell is proper
enviro_check() {
  debug_msg "enviro_check ($@)"
  if [ -z "$SHELL" ] || [ "$USER" != "root" ] ; then
    message "${PROBLEM_COLOR}WARNING:${DEFAULT_COLOR}${MESSAGE_COLOR}" \
            "You are not running a fully initialized root shell, consider" 
    message "running a proper root shell with 'su -'" \
            "${DEFAULT_COLOR}"
  fi
}

# function : root_check
# usage    : root_check
# purpose  : check if the user is root
root_check() {
  debug_msg "root_check ($@)"
  if [ "$UID" != "0" ] ; then
    message "${PROBLEM_COLOR}ERROR:${DEFAULT_COLOR}${MESSAGE_COLOR}" \
            "User must have root privileges to run this program" \
            "${DEFAULT_COLOR}"
    exit 1
  fi
}


# function : set_priority
# usage    : set_priority
# purpose  : force niceness on lunar's processes
set_priority() {
  debug_msg "set_priority ($@)"
  LUNAR_PRIORITY=${LUNAR_PRIORITY:="+10"}
  renice "$LUNAR_PRIORITY" -p $$ 2> /dev/null >/dev/null
}



--- NEW FILE: install.lunar ---
#!/bin/bash
############################################################
#                                                          #
# install.lunar - install Lunar modules                    #
#                                                          #
############################################################
# cast is part of the sorcery spell management utility     #
# Copyright 2001 by Kyle Sallee                            #
############################################################
#                                                          #
# this WAS the cast 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Parts Copyrighted Jason Johnston  2002 under GPLv2       #
#                                                          #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################


check_blacklist() {
  debug_msg "check_blacklist ($@)"
  #Copyrighted Jason Johnston  2002 under GPLv2

  # This checks the /var/state/lunar/gcc.<platform>
  # file to see if it exists.  If it does exist then
  # we grep it to see the names of the modules that
  # DO NOT compile with gcc 3x.  If the module is
  # on the list, we set the path so that gcc 3x is
  # NOT used.

  # If you find a module that does not compile with
  # gcc 3x please email your findings to
  # maintainer at lunar-linux.org.

  # Usage check_checklist $MODULES
  if [ -z "$PLATFORM" ] ; then
    PLATFORM=x86
  fi
  if [ -f /var/state/lunar/blacklist.$PLATFORM ] ; then
    BLKLST=$(grep ^$MODULE$ /var/state/lunar/blacklist.$PLATFORM)
    if [ "$BLKLST" == "$MODULE" ] ; then
      message "${PROBLEM_COLOR}! Module ${DEFAULT_COLOR}${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${PROBLEM_COLOR} is blacklisted and will not be installed${DEFAULT_COLOR}"
      exit 0
    fi
  else
    touch /var/state/lunar/blacklist.$PLATFORM
  fi
}


run_conflicts() {
  debug_msg "run_conflicts ($@)"
  run_module_file $MODULE CONFLICTS
}


# create the dependency files if they do not exist
prepare_depends_status()  {
  debug_msg "prepare_depends_status ($@)"
  [ -f $DEPENDS_STATUS ]        || touch  $DEPENDS_STATUS
  [ -f $DEPENDS_STATUS_BACKUP ] || touch  $DEPENDS_STATUS_BACKUP
}


prepare_module_config()  {
  debug_msg "prepare_module_config ($@)"
  if [ ! -x "$MODULE_CONFIG" ] ; then
    touch $MODULE_CONFIG
    chmod a+x $MODULE_CONFIG
  fi
}


# run the CONFIGURE script
run_configure() {
  debug_msg "run_configure ($@)"
  if [ -n "$RECONFIGURE" ];  then
    verbose_msg "Reconfiguring \"$MODULE\""
    rm -f $DEPENDS_CONFIG/$MODULE
    remove_depends $MODULE
  fi

  prepare_module_config

  if ! use_xinetd ; then
    if [ -n "$RECONFIGURE" ] || ! grep -q INITDSCRIPTS $MODULE_CONFIG ; then
      use_initd
    fi
  fi
  grep -q "^"$MODULE"\$" $TEMP_PREPAREDDEPS 2>/dev/null && return 0
  run_module_file $MODULE CONFIGURE
}


run_pre_build() {
  debug_msg "run_pre_build ($@)"
  message "${MESSAGE_COLOR}Building ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}"

  cd $BUILD_DIRECTORY

  if verify_all_sources $MODULE ; then
    if [ -s $SCRIPT_DIRECTORY/PRE_BUILD ] ; then
      run_module_file $MODULE PRE_BUILD
    else
      if ! default_pre_build ; then
        return 1
      fi
    fi
  else
    return 1
  fi
}


stop_logging() {
  debug_msg "stop_logging ($@)"
  message  "${MESSAGE_COLOR}Creating"                        \
           "${FILE_COLOR}$COMPILE_LOGS/$MODULE-$VERSION.bz2"  \
           "${DEFAULT_COLOR}"

  bzip2 -9f < $C_LOG > $COMPILE_LOGS/$MODULE-$VERSION.bz2
  temp_destroy $C_LOG
  temp_destroy $C_FIFO
}


start_logging () {
  debug_msg "start_logging  ($@)"
  export C_LOG=$(temp_create "${MODULE}.compile-log")
  export C_FIFO=$(temp_create "${MODULE}.compile-fifo")

  # just remaking this as FIFO
  rm -f $C_FIFO
  mknod $C_FIFO p
  echo "Compile log for \"$MODULE\"-\"$VERSION\" Built on \"$(date  -u)\"" > $C_LOG

  activate_voyeur
}


activate_voyeur()  {
  debug_msg "activate_voyeur ($@)"
  if [ -z "$SILENT" ] ; then
    case $VOYEUR in
      on) tee -a $C_LOG < $C_FIFO              & ;;
       *) tee -a $C_LOG < $C_FIFO >/dev/null   & ;;
    esac
  else
    tee -a $C_LOG < $C_FIFO >/dev/null &
  fi
}


run_build()  {
  debug_msg "run_build ($@)"
  if [ -d "$SOURCE_DIRECTORY" ] ; then
    cd $SOURCE_DIRECTORY
  fi

  verbose_msg "building \"$MODULE\" version \"$VERSION\" in `pwd`"
  
  if [ -x ./configure ] || [ -x ./src/configure ] ; then
    if [ -f /var/lib/lunar/localsaconfig ]; then
      if [ -f /var/cache/config/$MODULE ] ; then
        message "${MESSAGE_COLOR}These are your current -- config options for module ${MODULE_COLOR}$MODULE"
        message "${FILE_COLOR}(/var/cache/config/$MODULE)"
        cat /var/cache/config/$MODULE
      fi
	  
      if query "Do you wish to add -- options to ./configure?" n ; then
        edit_file /var/cache/config/$MODULE
        OPTS="$OPTS $(cat /var/cache/config/$MODULE)"
        message "${MESSAGE_COLOR} OPTS= ${MODULE_COLOR}$OPTS"
      fi
    fi
  fi

  if [ -s $SCRIPT_DIRECTORY/BUILD ] ; then
    run_module_file $MODULE BUILD
  else
    default_build
  fi

}


run_post_build() {
  debug_msg "run_post_build ($@)"
  if [ -s $SCRIPT_DIRECTORY/POST_BUILD ] ; then
    run_module_file $MODULE POST_BUILD
  fi
  default_post_build
}


run_post_install() {
  debug_msg "run_post_install ($@)"
  if [ -s $SCRIPT_DIRECTORY/POST_INSTALL ] ; then
    run_module_file $MODULE POST_INSTALL
  fi
}


export_ld()  {
  debug_msg "export_ld ($@)"
  for  DIRECTORY  in  $*;  do
    if  file  -b  $DIRECTORY/*.so*  |
        grep  -q  "shared object"
    then
      if  [  -z  "$LD_LIBRARY_PATH"  ]
      then  export  LD_LIBRARY_PATH="$DIRECTORY"
      else  export  LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DIRECTORY"
      fi
    fi
  done
}



show_owner()  {
  debug_msg "show_owner ($@)"
  OWNER=`grep  $TARGET  $INSTALL_LOGS/*  |
         cut  -d :  -f1                  |
         sed  -n  1p`
  if  [  -n  "$OWNER"  ];  then  echo  "`basename  $OWNER`"
                           else  echo  "nobody"
  fi
}


remove_line()  {
  debug_msg "remove_line ($@)"
  F_TMP=$(temp_create "${MODULE}.remove-line")
  cp $I_LOG $F_TMP
  grep -v $ITEM $F_TMP > $I_LOG
  temp_destroy $F_TMP

  message  "Symbolic link: ${SYMLINK_COLOR}${ITEM}${DEFAULT_COLOR}"  \
           "is owned by ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
  message  "Target of symbolic link is ${FILE_COLOR}${TARGET}${DEFAULT_COLOR}"
  message  "${FILE_COLOR}${TARGET}${DEFAULT_COLOR} is owned by `show_owner`"
  message  "Removed: ${SYMLINK_COLOR}${ITEM}${DEFAULT_COLOR} from ${I_LOG}"
}


resurrect()  {
(
  debug_msg "resurrect ($@)"

  if [ -s /etc/lunar/local/optimizations ] ; then
    . /etc/lunar/local/optimizations
  fi
  if ! run_details $1 ; then
    return 1
  fi
  run_conflicts    &&
  satisfy_depends  &&

  STATUS=installed &&

  if module_held $MODULE ; then
    VERSION=`installed_version $MODULE`
    STATUS=held
    lrm --keepconfig $MODULE
  fi &&

  CACHE_BZ="$INSTALL_CACHE/$MODULE-$VERSION-$BUILD.tar.bz2"

  if [ -f "$CACHE_BZ" ] && bzip2 -tf $CACHE_BZ ; then
    message  "${RESURRECT_COLOR}Resurrecting ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR} ${MESSAGE_COLOR}version ${VERSION_COLOR}${VERSION}${DEFAULT_COLOR}"
    bzip2 -cd $CACHE_BZ | tar -Pkx 1>/dev/null 2>&1
    add_module $MODULE $STATUS $VERSION
    verbose_msg "running \"lunar fix $MODULE\""
    run_fix $MODULE
    activity_log  "lin"  "$MODULE"  "$VERSION"  "success"
    message  "${RESURRECT_COLOR}Resurrected ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR} ${MESSAGE_COLOR}succesfully${DEFAULT_COLOR}"
  else
    false
  fi
)
}


show_download_progress()  {
  debug_msg "show_download_progress ($@)"
  if [ -f "$TEMP_DOWNLOADLOG" ] ; then
    if [ -z "$LC_OLD" ] ; then
      LC_OLD=0
    fi

    LC=`cat $TEMP_DOWNLOADLOG 2>/dev/null | wc -l | tr -d ' '`

    if [ "$LC" != "$LC_OLD" ] ; then
      (( LC_OLD++ ))
      sed  -n ${LC_OLD},${LC}p $TEMP_DOWNLOADLOG
      LC_OLD=$LC
    fi
  fi
}


show_downloading() {
  debug_msg "show_downloading ($@)"
  if [ -e "$TEMP_DOWNLOADLOG" ] ; then
    verbose_msg "====== download progess:"
    while ! lget $MODULE >> $TEMP_DOWNLOADLOG 2>&1 ; do
      show_download_progress
      sleep 1
    done
    show_download_progress
    verbose_msg "====== end download progress"
  fi
}



lin_module()  {
(
  debug_msg "lin_module ($@)"
  # make sure we got all the info
  if ! run_details $1 ; then
    return 1
  fi

  # resurrect if we can, but not is -c was issued
  if [ "$AUTORESURRECT" == "on" -a -z "$COMPILE" ] ; then
    # we also do not resurrect if $MODULE is currently installed!
    if ! module_installed $MODULE ; then
      if resurrect $MODULE ; then
        return 0
      fi
    fi
  fi

  # make sure we have the source code
  download_module $MODULE
  
  # set the installwatchfile
  export INSTALLWATCHFILE=$(temp_create "$MODULE.installwatch")

  # lock the module for installation, check for moonbase call
  linING="/var/lock/installing.$MODULE"
  if [ "$MODULE" == "moonbase" ] ; then
    if ! current_locked && ! solo_locked ; then
      echo $$ > $linING       &&
      get_moonbase            &&
      rm -f $linING           &&
      return
    else
      exit 1
    fi
  fi
  check_blacklist             &&
  
  # here we run CONFLICTS, DEPENDS and CONFIGURE stuff
  run_conflicts               &&
  satisfy_depends             &&
  show_downloading            &&

  # now entering the physical BUILD stage
  if ! current_locked && ! solo_locked ; then
    echo $$ > $linING  &&
    start_logging  &&

    if ! run_pre_build ; then
      LIN_ERROR="PRE_BUILD"
    else

      # important stuff here!!!
      invoke_installwatch &&
      if [ -z "$CFLAGS" ] ; then
        optimize
      fi  &&
      
      if ! run_build ; then
        LIN_ERROR="BUILD"
      else
        if ! run_post_build ; then
          LIN_ERROR="POST_BUILD"
	fi
      fi
    fi

    devoke_installwatch
    stop_logging
    
    if [ -n "$LIN_ERROR" ] ; then
      if [ -f "$INSTALLWATCHFILE" ] ; then
        temp_destroy $INSTALLWATCHFILE
      fi
      sound FAILURE
      message "${PROBLEM_COLOR}! Problem detected during ${FILE_COLOR}$LIN_ERROR${DEFAULT_COLOR}"
      rm -f $linING
      report $COMPILE_LOGS/$MODULE-$VERSION.bz2 "compile log" $MODULE $VERSION
      activity_log  "lin"  "$MODULE"  "$VERSION"  "failed" "Due to build errors during $LIN_ERROR"
      return 1
    fi  

    if ! boost ; then
      LIN_ERROR="boost"
    else
      if ! run_post_install ; then
        LIN_ERROR="POST_INSTALL"
      fi
    fi
    if [ -f "$INSTALLWATCHFILE" ] ; then
      verbose_msg "removing installwatch file"
      temp_destroy $INSTALLWATCHFILE
    fi

    if [ -n "$LIN_ERROR" ] ; then
      sound FAILURE
      message "${PROBLEM_COLOR}! Problem detected during ${FILE_COLOR}$LIN_ERROR${DEFAULT_COLOR}"
      rm -f $linING
      report $COMPILE_LOGS/$MODULE-$VERSION.bz2 "compile log" $MODULE $VERSION
      activity_log  "lin"  "$MODULE"  "$VERSION"  "failed" "Due to build errors during $LIN_ERROR"
      return 1
    fi

    rm_source_dir               &&
    report $INSTALL_LOGS/$MODULE-$VERSION "install log" $MODULE $VERSION &&
    rm -f $linING               &&
    sound SUCCESS               &&
    activity_log  "lin"  "$MODULE"  "$VERSION"  "success"

    if [ "$?" != 0 ] ; then
      sound FAILURE
      message "${PROBLEM_COLOR}! Problem detected${DEFAULT_COLOR}"
      rm -f $linING
      report $COMPILE_LOGS/$MODULE-$VERSION.bz2 "compile log" $MODULE $VERSION
      activity_log  "lin"  "$MODULE"  "$VERSION"  "failed" "Due to build errors during or after $LIN_ERROR"
      return 1
    fi
  fi
)
}


lin_locked()  {
  debug_msg "lin_locked ($@)"
  [     -f        /var/lock/installing.$1  ]  &&
  ps        `cat  /var/lock/installing.$1`    |
  grep  -q  "lin"
}


solo_locked()  {
  debug_msg "solo_locked ($@)"
  for SOLO_MODULE in `cat $SOLO` ; do
    if lin_locked $SOLO_MODULE ; then
      message  "${PROBLEM_COLOR}lining${DEFAULT_COLOR}"  \
               "of other modules is disabled during a"     \
               "lin ${MODULE_COLOR}${SOLO_MODULE}"         \
               "${DEFAULT_COLOR}"
      return
    fi
  done
  false
}


current_locked() {
  debug_msg "current_locked ($@)"
  if  lin_locked  $MODULE;  then
    message  "${QUERY_COLOR}Detected lin lock file: ${FILE_COLOR}${linING}${MESSAE_COLOR}"
    message  "${MESSAGE_COLOR}Now waiting for ${MODULE_COLOR}${MODULE}${DEFAULTT_COLOR}${MESSAGE_COLOR} to finish installing or for the lock to clear."

    while  lin_locked  $MODULE;  do  sleep  2;  done
    false
  else
    false
  fi
}


build_module_depends() {
(
  debug_msg "build_module_depends ($@)"
  run_details $1 &&
  run_configure &&
  run_depends &&
  satisfy_depends
)
}


build_depends()  {
  debug_msg "build_depends ($@)"
  for MODULE in $@ ; do
    if ! module_installed $MODULE || [ ! -n "$PROBE" ] ; then
      if ! module_held $MODULE ; then
        build_module_depends $MODULE
      else
        verbose_msg "Skipping dependency checking of held module \"$MODULE\""
      fi
    fi
  done
}




--- NEW FILE: main.lunar ---
#!/bin/bash
#                                                          #
# This code is written for Lunar Linux, see                #
# http://www.lunar-linux.org                               #
#                                                          #
############################################################
#                                                          #
# $FUNCTIONS/main.lunar                                    #
# contains all main handling code, aka the long complex    #
# functions like renew, update, fix, etc. One day they all #
# will be in here.                                         #
#                                                          #
############################################################
#                                                          #
# Copyrighted Auke Kok 2003 under GPLv2                    #
#                                                          #
############################################################

# function : renew
# usage    : renew
# purpose  : frontend function that includes all renewing code
renew() {
  debug_msg "renew ($@)"
  message "${MESSAGE_COLOR}Starting update of installed modules${DEFAULT_COLOR}"

  purge_modules
  
  export TMP_LIN_SUCCESS=$(temp_create "successfull")
  export TMP_LIN_FAIL=$(temp_create "failed")
      
  update_modules

  if [ "$AUTOFIX" == "on" ] ; then
    message "${MESSAGE_COLOR}Executing AUTOFIX : lin --fix${DEFAULT_COLOR}"
    lin --fix
  fi

  if [ "$AUTOPRUNE" == "on" ] ; then
    message "${MESSAGE_COLOR}Executing AUTOPRUNE : lunar prune${DEFAULT_COLOR}"
    prune
  fi

  display_update_log

  temp_destroy $TMP_LIN_SUCCESS
  temp_destroy $TMP_LIN_FAIL

}


update() {
  debug_msg "update ($@)"
  if  ps  -C  lin  >  /dev/null;  then
    echo    "Unable to update lunar concurrently while installing."
    sleep   5
    return  1
  fi

  lin moonbase
  if (( $(lvu installed $LUNAR_MODULE) < $(lvu version $LUNAR_MODULE) )) 
  then
    lin $LUNAR_MODULE && lunar renew
  else
    lunar renew
  fi

}


rebuild()  {
  debug_msg "rebuild ($@)"
  rm  -f  $INSTALL_QUEUE

  message  "To do a non recursive rebuild"
  message  "all installed modules must be fixed first."
  sleep  3
  $LIN  --fix

  for  LINE  in  `cat  $MODULE_STATUS_BACKUP`;  do
     MODULE=`echo  "$LINE"  |  cut  -d : -f1`
     STATUS=`echo  "$LINE"  |  cut  -d : -f3`
    if  [  "$STATUS"   ==  "installed"  ]   &&
        [  "$MODULE"  !=  "$LUNAR_MODULE"      ];  then
      echo  $MODULE  >>  $INSTALL_QUEUE
    fi
  done

  message  "Sorting the dependencies, that may take some time"
  sort_install_queue

  unset  MODULE
  if    query  "Edit Rebuild/Install Queue?" n
  then  edit_file  $INSTALL_QUEUE
  fi

  $LIN  --compile  `cat  $INSTALL_QUEUE`
  rm -f                  $INSTALL_QUEUE
}


# function : prune
# usage    : prune
# purpose  : prune all old logs, source copy's, install caches
prune() {
  debug_msg "prune ($@)"
  message  "${MESSAGE_COLOR}Generating a keep list..." \
           "${DEFAULT_COLOR}"

  KEEP="/tmp/prune.keep.$$"
  trap "rm -f $KEEP 2>/dev/null; exit" INT QUIT TERM
  generate_keep_list

  message  "${MESSAGE_COLOR}Now pruning $SOURCE_CACHE..." \
           "${DEFAULT_COLOR}"
  ls  $SOURCE_CACHE  |
  while  read  FILE;  do
      grep  -q  "^$FILE$"  $KEEP  || {
        rm  $SOURCE_CACHE/$FILE 2>/dev/null
	verbose_msg "rm \"$SOURCE_CACHE/$FILE\""
      }
  done

  message  "${MESSAGE_COLOR}Now pruning $INSTALL_CACHE..." \
           "${DEFAULT_COLOR}"
  ls  $INSTALL_CACHE  |
  while  read  FILE;  do
      grep  -q  "^$FILE$"  $KEEP  || {
        rm  $INSTALL_CACHE/$FILE 2>/dev/null
	verbose_msg "rm \"$INSTALL_CACHE/$FILE\""
      }	
  done

  KEEP2="/tmp/prune.instlist.$$"
  trap "rm -f $KEEP2 2>/dev/null; exit" INT QUIT TERM
  cat $MODULE_STATUS | cut -d: -f1,4 | sed 's/:/-/' > $KEEP2

  message  "${MESSAGE_COLOR}Now pruning $INSTALL_LOGS..." \
             "${DEFAULT_COLOR}"
  ls  $INSTALL_LOGS  |
  while  read  FILE;  do
      grep -q "^$FILE$"   $KEEP2 || {
        rm $INSTALL_LOGS/$FILE
	verbose_msg "rm \"$INSTALL_LOGS/$FILE\""
      }
  done

  message  "${MESSAGE_COLOR}Now pruning $COMPILE_LOGS..." \
             "${DEFAULT_COLOR}"
  ls  $COMPILE_LOGS  | sed 's/.bz2$//' |
  while  read  FILE;  do
      grep -q "^$FILE$"    $KEEP2 || {
        rm $COMPILE_LOGS/$FILE.bz2
	verbose_msg "rm \"$COMPILE_LOGS/$FILE\""
      }
  done

  message  "${MESSAGE_COLOR}Now pruning $MD5SUM_LOGS..." \
             "${DEFAULT_COLOR}"
  ls  $MD5SUM_LOGS  |
  while  read  FILE;  do
      grep -q "^$FILE$"    $KEEP2 || {
        rm $MD5SUM_LOGS/$FILE
	verbose_msg "rm \"$MD5SUM_LOGS/$FILE\""
      }
  done

  rm  -f  $KEEP 2>/dev/null
  rm  -f  $KEEP2 2>/dev/null
  trap INT QUIT TERM
}


resurrect_modules() {
  debug_msg "resurrect_modules ($@)"
  for MODULE in $@ ; do
    if run_details $MODULE ; then
      resurrect $MODULE
    fi
  done
}

--- NEW FILE: misc.lunar ---
#!/bin/bash
#                                                          #
# misc.lunar - Lunar subroutines                           #
#                                                          #
############################################################
#                                                          #
# this WAS the subroutines 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Copyright 2001 by Kyle Sallee                            #
#                                                          #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2        #
#                                                          #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################



# function : directories
# usage    : VARIABLE=`directories < dirlistfile`
# purpose  : to determine the directories from a given list
directories() {
  debug_msg "directories ($@)"
  while read ITEM ; do
    if [ -d "$ITEM" ] && [ ! -h "$ITEM" ] ; then
      echo "$ITEM"
    fi
  done
}


# function : files
# usage    : VARIABLE=`files < dirlistfile`
# purpose  : to determine the ordinary files from a given list
files() {
  debug_msg "files ($@)"
  while read ITEM ; do
    if [ -f "$ITEM" ] && [ ! -h "$ITEM" ] ; then
      echo "$ITEM"
    fi
  done
}


# function : sysmlinks
# usage    : VARIABLE=`symlinks < dirlistfile`
# purpose  : to determine the symbolic links from a given list
symlinks() {
  debug_msg "symlinks ($@)"
  while read ITEM ; do
    if [ -h "$ITEM" ] ; then
      echo "$ITEM"
    fi
  done
}


# function : dirnames
# usage    : VARIABLE=`dirnames < dirlistfile`
# purpose  : info about the real locations of symlinks
dirnames() {
  debug_msg "dirnames ($@)"
  while read FILE ; do
    dirname "$FILE"
  done
}


# function : exists
# usage    : VARIABLE=`exists < dirlistfile`
# purpose  : filter out the non-existent files in a list
exists() {
  debug_msg "exists ($@)"
  while read ITEM ; do
    if [ -e "$ITEM" ] ; then
      echo $ITEM
    fi
  done
}


# function : guess_filename
# usage    : guess_filename <filename>
# purpose  : fuzzy check for the existance of the filename
guess_filename()  {
  debug_msg "guess_filename ($@)"
  FILENAME=$1
  BASENAME=${FILENAME/.tar.gz/}
  BASENAME=${BASENAME/.tar.bz2/}
  BASENAME=${BASENAME/.tgz/}

  if [ -f "$FILENAME" ] ; then
    debug_msg "guess_filename: $FILENAME"
    echo $FILENAME
  elif [ "$FUZZY" == "off" ] ; then
    return 1
  elif [ -f "$BASENAME.tar.gz" ] ; then
    debug_msg "guess_filename: $BASENAME.tar.gz"
    echo $BASENAME.tar.gz
  elif [ -f "$BASENAME.tar.bz2" ] ; then
    debug_msg "guess_filename: $BASENAME.tar.bz2"
    echo $BASENAME.tar.bz2
  elif [ -f "$BASENAME.tgz" ] ; then
    debug_msg "guess_filename: $BASENAME.tgz"
    echo $BASENAME.tgz
  else
    return 1
  fi
}


# function : filter
# usage    : filter $FILE
# purpose  : filter stdin with files/dirs/symlinks provided in file $1.
filter() {
  debug_msg "filter ($@)"
  if [ -f "$1" ] ; then
    grep -v $(
      for DIR in `directories < $1 2>/dev/null` ; do
        echo -n "^$DIR\|"
      done
      for FILE in `files < $1 2>/dev/null` ; do
        echo -n "^$FILE\$\|"
      done
      for SYM in `symlinks < $1 2>/dev/null` ; do
        echo -n "^$SYM\$\|"
      done
      echo -n "/dev/null"
      )
  else
    cat
  fi

}



--- NEW FILE: prune.lunar ---
#!/bin/bash
#                                                          #
# prune.lunar - Lunar prune code                           #
#                                                          #
############################################################
#                                                          #
# this WAS the subroutines 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Copyright 2001 by Kyle Sallee                            #
#                                                          #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2        #
#                                                          #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################


# function : generate_keep_list
# usage    : generate_keep_list
# purpose  : generated a list of files which will not be deleted with prune
generate_keep_list() {
  debug_msg "generate_keep_list ($@)"
  for MODULE in $(list_moonbase | sort);  do
    show_fancy_progress "Processing: $MODULE"
    sources $MODULE >> $KEEP
    VERSION=$(installed_version $MODULE)
    if [ -z "$VERSION" ] ; then
      VERSION=$(run_details $MODULE ; echo $VERSION)
    fi
    echo $MODULE-$VERSION-$BUILD.tar.bz2 >> $KEEP
  done
  
  echo  README >> $KEEP
}





--- NEW FILE: temp.lunar ---
#!/bin/bash
#                                                                  #
# temp.lunar - lunar temp code handling                            #
#                                                                  #
####################################################################
#                                                                  #
# Copyright 2003 - Auke Kok under GPLv2                            #
#                                                                  #
####################################################################
#                                                                  #
# temp.lunar contains uniform temporary file name creation and     #
# tracking. All lunar tools MUST use these functions if they wish  #
# to perform temporary file operations                             #
#                                                                  #
# functions: temp_create, temp_destroy                             #
#                                                                  #
####################################################################


temp_create() {
  debug_msg "temp_create ($@)"
  TMPDIR=${TMPDIR:-/var/tmp}
 
  if TMPFILE=$(mktemp -p "$TMPDIR" -t lunar.`basename $0`.$$.$1.XXXXXXXXXX ) ; then
    echo $TMPFILE
  else
    message "${PROBLEM_COLOR}ERROR:${NORMAL_COLOR}${DEFAULT_COLOR}" \
            "Cannot create temp file${NORMAL_COLOR}"
    exit 1
  fi  
}


temp_destroy() {
  debug_msg "temp_destroy ($@)"
  if [ -e "$1" ] ; then
    rm -f "$1"
  fi
}



--- NEW FILE: tracking.lunar ---
#!/bin/bash
#                                                          #
# subroutines - Lunar subroutines                          #
#                                                          #
############################################################
#                                                          #
# this WAS the subroutines 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 at tsrsb.org.tr>, 20020519             #
#                                                          #
############################################################
#                                                          #
# Copyright 2001 by Kyle Sallee                            #
#                                                          #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2        #
#                                                          #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2          #
#                                                          #
############################################################


boost_locked() {
  debug_msg "boost_locked ($@)"
  [ -f $BOOST_LOCK ] && ps `cat $BOOST_LOCK` | grep -q lin
}


# function : invoke_installwatch
# usage    : invoke_installwatch
# purpose  : start logging all disk accesses with installwatch
invoke_installwatch() {
  debug_msg "invoke_installwatch ($@)"
  if [ -e /usr/lib/installwatch.so ] ; then
    export LD_PRELOAD=/usr/lib/installwatch.so
  fi
}


# function : devoke_installwatch
# usage    : devoke_installwatch
# purpose  : stop logging all disk accesses with installwatch
devoke_installwatch() {
  debug_msg "devoke_installwatch ($@)"
  unset LD_PRELOAD
}


# function : parse_iw
# usage    : parse_iw
# purpose  : remove unwanted accesses from the installwatch file
parse_iw() {
  debug_msg "parse_iw ($@)"
  OMIT="^/dev\|^/tmp\|^/usr/src"
  OMIT_IN="	rename\|	symlink\|	unlink"

  grep -v "$OMIT_IN" $INSTALLWATCHFILE | cut -f3 | grep -v "$OMIT"
  cat                $INSTALLWATCHFILE | cut -f4 | grep -v "$OMIT" | grep "^/"
}


# function : create_install_log
# usage    : create_install_log
# purpose  : create an install log
create_install_log() {
  debug_msg "create_install_log ($@)"

  TMP_INST_LOG=$(temp_create "install-log")
  INST_LOG="$INSTALL_LOGS/$MODULE-$VERSION"
  rm -f $INST_LOG &> /dev/null

  message  "${MESSAGE_COLOR}Creating ${FILE_COLOR}${INST_LOG}${DEFAULT_COLOR}"

  export IFS="$TAB_ENTER_IFS"

  parse_iw                   |
  sort                       |
  uniq                       |
  filter  "$EXCLUDED"        |
  filter  "$LOCAL_EXCLUDED"  |
  exists                     >  $TMP_INST_LOG

  echo "$INSTALL_LOGS/$MODULE-$VERSION"                 >> $TMP_INST_LOG
  echo "$COMPILE_LOGS/$MODULE-$VERSION.bz2"             >> $TMP_INST_LOG
  echo "$MD5SUM_LOGS/$MODULE-$VERSION"                  >> $TMP_INST_LOG

  MISOWNED_SYMLINKS=$(syms_not_owned  $TMP_INST_LOG
                      echo  -n  "/dev/null")

  if [ "$MISOWNED_SYMLINKS" == "/dev/null" ] ; then
    install -m644 $TMP_INST_LOG $INST_LOG
  else
    grep -v "$MISOWNED_SYMLINKS" $TMP_INST_LOG > $INST_LOG
  fi

  temp_destroy $TMP_INST_LOG
}


create_md5sum_log()  {
  debug_msg "create_md5sum_log ($@)"

  rm -f $MD5SUM_LOGS/$MODULE-$VERSION &> /dev/null
  
  message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$MD5SUM_LOGS/$MODULE-$VERSION${DEFAULT_COLOR}"

  files < $INSTALL_LOGS/$MODULE-$VERSION | while read FILE ; do
    md5sum $FILE >> $MD5SUM_LOGS/$MODULE-$VERSION
  done

}

create_install_cache() {
  debug_msg "create_install_cache($@)"

  if [ "$ARCHIVE" == "off" ] ; then
    return
  fi

  message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$INSTALL_CACHE/$MODULE-$VERSION-$BUILD.tar.bz2${DEFAULT_COLOR}"
  tar cPjf "$INSTALL_CACHE/$MODULE-$VERSION-$BUILD.tar.bz2" --no-recursion -T $INSTALL_LOGS/$MODULE-$VERSION

}


boost()	{
  debug_msg "boost ($@)"

  create_install_log    &&
  create_md5sum_log     &&
  create_install_cache  &&
  
  add_module $MODULE installed $VERSION $(find_module_size $MODULE $VERSION)
  verbose_msg "module size is $(find_module_size $MODULE $VERSION)"

  rm  -f  $BOOST_LOCK

}






More information about the Lunar-commits mailing list