CVS: brutus/elaine/lunar+versions lrm,NONE,1.1 lvu,NONE,1.1

elaine at lunar-linux.org elaine at lunar-linux.org
Sun Sep 7 12:12:32 GMT 2003


Update of /var/cvs/lunar/brutus/elaine/lunar+versions
In directory dbguin.lunar-linux.org:/tmp/cvs-serv24231

Added Files:
	lrm lvu 
Log Message:
hacks to make lvu/lrm work with module/v.v form modules, fixed failure
to set SIZE in state/lunar/packages Dependencies seem to work now


--- NEW FILE: lrm ---
#!/bin/bash
############################################################
#                                                          #
# This code is written for Lunar Linux, see                #
# http://www.lunar-linux.org                               #
#                                                          #
############################################################
#                                                          #
# lrm is for removing installed packages                   # 
#                                                          #
# 20020610                                                 #
#                                                          #
############################################################
#                                                          #
# Copyrighted Kagan Kongar 2002 under GPLv2                #
#                                                          #
############################################################

help() {
cat << END
usage: lrm [options] [module ...]
   -d | --debug         Enables debug messages
   -D | --downgrade [module] [version] downgrades a module
   -h | --help          Displays this help text
   -k | --keepconfig    remove module(s) but keep dependencies and config
   -n | --nosustain     removes module(s) even if they are sustained
   -v | --verbose       Increases the level of message output
   
lrm is a script for removing installed modules.
   If invoked without options, lrm will remove all installed files 
belonging to the module(s) and remove the module(s) from the list
of installed modules. 
   Downgrading a module means removing the current installed version
of the module and installing a specific version; given that the 
specific version is already in $INSTALL_CACHE/.
   Some modules (such as bash and gcc)  are marked "non-removable" by the 
system. In order to remove "sustained" modules, use the nosustain option.
END
exit 1
}


exit_proc() {
  debug_msg "exit_proc ($@)"
  temp_destroy $LRM_QUEUE
  temp_destroy $LRM_TEMP
  temp_destroy $TEMP_FILE
  temp_destroy $TEMP2_FILE
  exit
}


trap_proc() {
  verbose_msg "Trapped a signal! "
  exit_proc
}


handle_config_files() {
  debug_msg "handle_config_files ($@)"
  TARGET="$1"
  if dirname "$TARGET" | grep -q "^/etc" ; then
    verbose_msg "Examining config file \"$TARGET\""

    TARGET_MD5=$(md5sum "$TARGET" | cut -d " " -f 1-1)
    OLD_MD5=$(grep -w "$TARGET\$" $MD5_LOG | cut -d " " -f 1-1)

    if [ -z "$TARGET_MD5" ] ; then
      verbose_msg "Skipping removal of \"$TARGET\" due to problem with md5sum"
      continue
    fi

    if [ -z "$OLD_MD5" ] ; then
      verbose_msg "Skipping removal of \"$TARGET\" due to missing original md5sum"
      continue
    fi

    if [ "$TARGET_MD5" == "$OLD_MD5" ] ; then
      verbose_msg "Removing \"$TARGET\""
      rm -f $TARGET
      continue
    fi

    if [ "$TARGET_MD5" != "$OLD_MD5" ] ; then
      verbose_msg "Skipping removal of \"$TARGET\" due to md5sum mismatch"
      if [ "$PRESERVE" == "on" ] ; then
         verbose_msg "PRESERVE=on, keeping \"$TARGET\""
         continue
      else
         verbose_msg "PRESERVE=off, archiving \"$TARGET\""
         mv $TARGET $TARGET.`date +%Y%m%d%H%M`
         continue
      fi
    fi
  fi
}

remove_something() {
  debug_msg "remove_something ($@)"
   if [ -z "$1" ]; then
     debug_msg "remove_something: No args, exiting"
     return 1
   fi

   if ! [ -e "$1" ] && ! [ -L "$1" ] ; then
     debug_msg "remove_something: no such file $1, exiting"
     return 1
   fi

   TARGET="$1"

   if [ -d "$TARGET" ] ; then
     rmdir $TARGET 2> /dev/null
   else
     rm -f $TARGET 2>/dev/null
   fi

   if [ "$?" == "0" ] ; then
     debug_msg "remove_something: removed $TARGET succesfully"
   else
     debug_msg "remove_something: removed $TARGET not succesful"
   fi
}

process_directories() {
  debug_msg "process_directories ($@)"

  if [ -z "$1" ]; then
    debug_msg "process_directories: No args, exiting"
    return 1
  fi

  cat $1 | sort -r | while read LINE ; do
    remove_something "$LINE"
  done
}


process_lrm_queue() {
  debug_msg "process_lrm_queue ($@)"

  export TEMP_FILE=$(temp_create "lrm")
  export TEMP2_FILE=$(temp_create "lrm")

  while [ -s "$LRM_QUEUE" ]
  do   
    MODULE=$(remove_queue $LRM_QUEUE)
    verbose_msg "${TEMP}removing \"$MODULE\""

    run_details $MODULE &> /dev/null

    VERSION=$(installed_version $MODULE)
    INST_LOG=$INSTALL_LOGS/$MODULE-$VERSION
    MD5_LOG=$MD5SUM_LOGS/$MODULE-$VERSION

    # time-out 1: PRE_REMOVE
    run_module_file $MODULE PRE_REMOVE 

    while read TARGET ; do
      if ! [ -e "$TARGET" ] ; then
        continue
      fi

      if grep -q -w "$TARGET\$" $PROTECTED $EXCLUDED ; then
        verbose_msg "\"$TARGET\" is protected or excluded!!"
        continue
      fi

      if [ -d "$TARGET" ] ; then
        echo "$TARGET" >> $TEMP_FILE
        continue
      fi

      handle_config_files $TARGET

      remove_something $TARGET

    done < $INST_LOG

    process_directories $TEMP_FILE $TEMP2_FILE

    # time-out 2: POST_REMOVE
    run_module_file $MODULE POST_REMOVE

    if [ "$KEEPCONFIG" == "on" ] ; then
      verbose_msg "skipping removal of dependency listing and configs"
    else
      verbose_msg "removing module from dependency listing and configs"
      remove_depends  $MODULE
    fi

    # administration duty time:
    verbose_msg "removing module from installed list.. "
    remove_module $MODULE

    message  "${LRM_COLOR}Removed${EXTEMP} module:"  \
             "${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"

    activity_log  "lrm"  "$MODULE" "$VERSION"  "success"
  done
}


check_status() {
   module_installed $MODULE || {
      message  "${MODULE_COLOR}${MODULE}"  \
      "${PROBLEM_COLOR}is not installed."  \
      "${DEFAULT_COLOR}"
      [ "$EXILE"   == "on" ] || return 1
   } 

   [ "$NOSUSTAIN" == "on" ] && return 0 || {

      verbose_msg "checking if \"$1\" is sustained"
      grep -q -w "$MODULE" "$SUSTAINED" && {
             message  "${MODULE_COLOR}${MODULE}"         \
                      "${PROBLEM_COLOR}is sustained."  \
                      "${DEFAULT_COLOR}"
            return 1 
      } || return 0 
   }
   true
}


downgrade() {
  # a local function for listing the contents of install cache
  list_available_cache() {
    ls -1 $INSTALL_CACHE/$MODULE-* | while read LINE ; do
      echo "$LINE"
    done
    exit 1
  }
   
  root_check || exit 1

  verbose_msg "running \"$MODULE\" DETAILS file"
  run_details $MODULE &> /dev/null || return 1

  if [ -z "$1" ] ; then
    echo "No version is entered. The below is the list of available files."
    list_available_cache   
  fi

  if [ ! -s $INSTALL_CACHE/$MODULE-$1-$BUILD.tar.bz2 ] ; then 
    echo "Desired version is not available. Here is the available files"
    list_available_cache
  fi

  verbose_msg "checking if \"$MODULE\" is installed"

  if [ -n "$(installed_version $MODULE)" ] ; then 
    verbose_msg "\"$(installed_version $MODULE)\" of \"$MODULE\" is installed at the moment"

    if [ "$1" == "$I_VERSION" ] ; then
      echo "The downgrade version is the same as the installed version"
      echo "Here is the available files." 
      list_available_cache
    fi

    verbose_msg "removing \"$MODULE-$(installed_version $MODULE)\""
    lrm -ts $MODULE || lrm -s $MODULE

  else
    verbose_msg "\"$MODULE\" is NOT installed at the moment"
  fi

  verbose_msg "installing \"$MODULE-$1\""
  verbose_msg "extracting cached install file..."
  
  bzcat $INSTALL_CACHE/$FILENAME | tar -kt $TAR_P -C / >/dev/null
  verbose_msg "adding module to installed list"

  bzcat $INSTALL_CACHE/$FILENAME | 
  tar -kx $TAR_P -C / 2>/dev/null >/dev/null
  verbose_msg "adding module to installed list"
  add_module $MODULE installed  $1
  activity_log  "lrm downgrade"  "$MODULE"  "$1"  "success"

  message  "${RESURRECT_COLOR}Downgraded module:"  \
           "${MODULE_COLOR}${MODULE}"              \
           "${DEFAULT_COLOR}"                      \
           "version"                               \
           "${VERSION_COLOR}${1}"                  \
           "${DEFAULT_COLOR}" 
   
  exit
}

create_lrm_queue() {

  [ "$#" == "0" ] && help;

   if [ "$TEST" != "on" ]; then 
      root_check || exit 1
   fi

   [ -e "$EXCLUDED" ] || {
      message  "${PROBLEM_COLOR} $EXCLUDED can't be found!!."  \
               "\nTouching it to create, but this is just a "  \
               "workaround!! \nDo a lunar update ASAP\n"       \
               "${DEFAULT_COLOR}"
      touch $EXCLUDED 
    }

   [ -e "$PROTECTED" ] || {
      message  "${PROBLEM_COLOR} $PROTECTED can't be found!!." \
               "\nTouching it to create, but this is just a "  \
               "workaround!! \nDo a lunar update ASAP\n"       \
               "${DEFAULT_COLOR}"
      touch $PROTECTED 
    }

  export LRM_QUEUE=$(temp_create "lrm-queue")
  export LRM_TEMP=$(temp_create "lrm")
                       
   MODULE_LIST="$@"
   for MODULE in $MODULE_LIST
   do
      check_status $MODULE  || continue
      add_queue $LRM_QUEUE $MODULE
   done      
}

. /etc/lunar/config



GETOPT_ARGS=$(getopt -q -n lrm -o "dD:hknv" -l "debug,downgrade:,help,keepconfig,nosustain,verbose" -- "$@")

if [ -z "$?" ] ; then
  help | view_file
  exit
else
  eval set -- $GETOPT_ARGS

  root_check 
  enviro_check
  set_priority

  while true ; do
   case "$1" in
     -d|--debug      ) (( LUNAR_DEBUG++ )) ; export LUNAR_DEBUG ; shift ;;
     -D|--downgrade  ) export DOWNGRADE="on"
                       export MODULE="$2"
                       shift 3
                       downgrade "${@#-}"
                       exit
                       break;;
     -h|--help       ) help  ;;
     -k|--keepconfig ) export KEEPCONFIG="on" ; shift ;;
     -n|--nosustain  ) export NOSUSTAIN="on" ; shift ;;
     -v|--verbose    ) export VERBOSE="on" ; shift ;;
     --) shift; break ;;
      *) help;  break ;;
   esac
  done

  verbose_msg "signals TERM, INT and QUIT are trapped"
  trap "trap_proc" INT QUIT TERM

  create_lrm_queue "${@#-}"
  process_lrm_queue
  exit_proc
fi


--- NEW FILE: lvu ---
#!/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 at 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
LVU -- Lunar View utility (for viewing just about everything in Lunar-Linux)

Usage:		lvu [general options] [command [command parameters]]

GENERAL OPTIONS:

-d  |  --debug                  Enables debug messages
-h  |  --help                   Displays this help text
-v  |  --verbose                Increases the level of message output

Commands:

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 given file
leafs                      display installed modules that have no explicit
                               dependencies on them
orphans                    display installed modules that are missing
                               dependencies
held                       display held modules
exiled                     display exiled modules

search      "phrase"       searches all modules long descriptions for phrase.
service     port|acronym   displays modules 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       restores an exported 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       20030801       display available modules newer than Aug 01, 2003
older       20030101       display modules installed before Jan 01, 2003

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 at 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)
      mv_edit $2
      if [ -n "$2" ] ; then
        if ! md5sum_files "$INSTALL_LOGS/$MOD_V_SNAME-$(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 at 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)
      mv_edit $2
      run_details $2 ; 
        if [ -f $COMPILE_LOGS/$MOD_V_SNAME-$(lvu version $2).bz2 ] ; then
          view_file $COMPILE_LOGS/$MOD_V_SNAME-$(lvu version $2).bz2
        else
          VERSION=$(installed_version $2)
          view_file $COMPILE_LOGS/$MOD_V_SNAME-$(installed_version $2).bz2 \
             "Compile log for $2 does not exist"
        fi
      #fi
      ;;
	      
   install)
     mv_edit $2
     if run_details $2 ; then
       view_file $INSTALL_LOGS/$MOD_V_SNAME-$(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







More information about the Lunar-commits mailing list