[Lunar-commits] CVS: theedge/var/lib/lunar/plugins download-cvs.plugin, NONE, 1.1 download-file.plugin, NONE, 1.1 download-generic.plugin, NONE, 1.1 download-svn.plugin, NONE, 1.1

Auke Kok sofar at lunar-linux.org
Wed Mar 23 16:18:15 UTC 2005


Update of /var/cvs/lunar/theedge/var/lib/lunar/plugins
In directory espresso.foo-projects.org:/home/sofar/active/theedge/var/lib/lunar/plugins

Added Files:
	download-cvs.plugin download-file.plugin 
	download-generic.plugin download-svn.plugin 
Log Message:
Adding a plugin system for downloading source code(tested). This codeset allows people to write plugins for other things later on.


--- NEW FILE: download-cvs.plugin ---
#!/bin/bash
############################################################
#                                                          #
# CVS downloading plugin - download-cvs.plugin             #
#                                                          #
############################################################
#                                                          #
# Copyright 2005 by Auke Kok under GPLv2                   #
#                                                          #
############################################################


plugin_source_download_cvs() {
  # check if we can handle this URL format
  if [ "${1:0:6}" != "cvs://" ] ; then
    return 2
  fi
  debug_msg "plugin_source_download_cvs($@)"

  if ! module_installed cvs ; then
    # full stop: we need to make sure the user sees this error:
		
    message "${PROBLEM_COLOR}! Cannot fetch CVS sources without \"cvs\" installed!${DEFAULT_COLOR}"
    exit 1
  fi

  [ -f ~/.cvspass ] || touch ~/.cvspass
  CVSURL=$(echo $1 | sed "s:^cvs\://::")
  CVSARGS=$(echo $CVSURL | cut -d@ -f1)
  CVSSERVER=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f1)
  CVSSPATH=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f2)
  CVSMODULE=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f3)
  CVSRELEASE=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f4)
  CVSOPTIONS=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f5)

  if [ ! -z "$CVSRELEASE" ]; then
    CVSRELEASE="-r $CVSRELEASE"
  fi

  CVSROOT="$CVSARGS@$CVSSERVER:$CVSSPATH"

  message  "${MESSAGE_COLOR}Downloading CVS module"                      \
           "${FILE_COLOR}${CVSMODULE}${DEFAULT_COLOR}${MESSAGE_COLOR}"   \
 	   "for module ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"

  mk_source_dir $TMPDIR/$MODULE-$VERSION
  cd $TMPDIR/$MODULE-$VERSION
  
  if [ -f "$2" ] ; then
    verbose_msg "Extracting local CVS copy"
    # unpacking in last component dir of $CVSMODULE
    CD=$(pwd -P)
    debug_msg "get_cvs: PWD=$PWD mkdir -p $(dirname $CVSMODULE)"
    mkdir -p $(dirname $CVSMODULE)
    cd $(dirname $CVSMODULE)
    debug_msg "get_cvs: PWD=$PWD tar xjf $2"
    if ! tar xjf $2 ; then
      message "${PROBLEM_COLOR}Warning: bad local CVS copy, checking out fresh CVS copy${DEFAULT_COLOR}"
      
      rm_source_dir $TMPDIR/$MODULE-$VERSION
      mk_source_dir $TMPDIR/$MODULE-$VERSION
      cd $TMPDIR/$MODULE-$VERSION
    else
      cd $TMPDIR/$MODULE-$VERSION/$CVSMODULE
    fi
  fi

  verbose_msg "CVSROOT=\"$CVSROOT\""

  NUM_RETRY=${NUM_RETRY:-5}
  if [ "$NUM_RETRY" -eq 0 ]; then
    NUM_RETRY=1000
  fi

  for (( TRY=1 ; $TRY<$NUM_RETRY+1 ; TRY++ )) ; do
    if [ -d CVS ] ; then
      verbose_msg "[${TRY}] cvs -qz3 up -PAd $CVSOPTIONS $CVSRELEASE"
      cvs -qz3 up -PAd $CVSOPTIONS $CVSRELEASE && GOT_CVS="yes" 
    else 
      verbose_msg "[${TRY}] cvs -d $CVSROOT -qz3 co $CVSOPTIONS $CVSRELEASE $CVSMODULE"
      cvs -d $CVSROOT -qz3 co $CVSOPTIONS $CVSRELEASE $CVSMODULE && GOT_CVS="yes"
    fi

    if [ "$?" == "0" ] ; then
      break
    fi

    sleep 2
  done
  
  if [ "$GOT_CVS" == "yes" ] ; then
    message "${MESSAGE_COLOR}Creating ${FILE_COLOR}${2}${DEFAULT_COLOR}"
    # pack in last component dir of $CVSMODULE
    cd $TMPDIR/$MODULE-$VERSION/$(dirname $CVSMODULE)
    tar cjf $2 $(basename $CVSMODULE)
    cd $CD
  else
    activity_log "lget"  "$MODULE"  "$VERSION"  "failed" "Could not get $CVSMODULE"
  fi

  cd $TMPDIR
  rm_source_dir $TMPDIR/$MODULE-$VERSION

}


plugin_source_needrefresh_cvs() {
  # check if we can handle this URL format
  if [ "${1:0:6}" != "cvs://" ] ; then
    return 2
  fi
  debug_msg "plugin_source_needrefresh_cvs($@)"

  if [ ! -f $2 ]; then
    return 0
  fi

  CVS_THRESHOLD=${CVS_THRESHOLD:-10}
  if (( "CVS_THRESHOLD" > 0 )) ; then
	if [ "$(find $2 -amin +$CVS_THRESHOLD)" == "$2" ] ; then
      # it is older:
	  return 0
	else
      verbose_msg "CVS update not required for \"$2\" (less than $CVS_THRESHOLD mins old)"
      # now we can send a FAIL so the next plugins are skipped:
	  return 1
    fi
  else
    # always return true if threshhold is zero
    return 0
  fi
}


plugin_register SOURCE_DOWNLOAD plugin_source_download_cvs
plugin_register SOURCE_NEEDREFRESH plugin_source_needrefresh_cvs



--- NEW FILE: download-file.plugin ---
#!/bin/bash
#############################################################
#                                                           #
# download-file.plugin - plugin that downloads file:// urls #
#                                                           #
#############################################################
#                                                           #
# Copyright 2005 by Auke Kok under GPLv2                    #
#                                                           #
#############################################################


plugin_source_download_file()  {
  # check if we can handle this type of URL:
  if [ ${1:0:7} != "file://" ]; then
    return 2
  fi
  debug_msg "plugin_source_download_file ($@)"

  cp $(echo $1 | sed 's/file:\/\///') $2
}


plugin_register SOURCE_DOWNLOAD plugin_source_download_file

--- NEW FILE: download-generic.plugin ---
#!/bin/bash
############################################################
#                                                          #
# download-generic.plugin - download http/ftp urls         #
#                                                          #
############################################################
#                                                          #
# Copyright 2005 by Auke Kok under GPLv2                   #
#                                                          #
############################################################


plugin_source_download_generic()  {
  # check if we can handle this type of URL:
  if [ ${1:0:7} != "http://" -a ${1:0:6} != "ftp://" ]; then
    return 2
  fi
  debug_msg "plugin_source_download_generic ($@)"

  # this is what the download will be stored as initially:
  TMP_FILE=$TMPDIR/$(basename $2)

  if [ "$FTP_ACTIVE" == "off" -o "$FTP_PASSIVE" == "on" ] ; then
    WGET_FTP_CONNECTION="--passive-ftp"
  fi

  if [ "$CONTINUE" == "off" ] ; then
    erase $TMP_FILE
  else
    WGET_PARTIAL="--continue"
  fi

  if [ "$USE_CACHE" == "off" ] ; then
    WGET_CACHE="--cache=off"
  else
    WGET_CACHE="--cache=on"
  fi

  if [ -n "$DOWNLOAD_RATE" ] ; then
    WGET_RATE="--limit-rate=${DOWNLOAD_RATE}"
  fi

  WGET_RETRIES="--tries=${WGET_NUM_RETRY:=5}"

  [ -n "$http_proxy" ] && export http_proxy=$http_proxy
  [ -n  "$ftp_proxy" ] && export  ftp_proxy=$ftp_proxy
  [ -n   "$no_proxy" ] && export   no_proxy=$no_proxy

  verbose_msg "calling \"wget $WGET_CACHE $WGET_RATE $WGET_FTP_CONNECTION $WGET_RETRIES $WGET_PARTIAL $1 --output-document $TMP_FILE\""
  if erase $TMP_FILE && wget $WGET_CACHE $WGET_RATE $WGET_FTP_CONNECTION $WGET_RETRIES $WGET_PARTIAL "$1" --output-document "$TMP_FILE" ; then
    # looks like it worked
    if testpack $TMP_FILE ; then
      install -m644 $TMP_FILE $(dirname $2)/$(basename $TMP_FILE)
      rm $TMP_FILE
      verbose_msg "download of \"$1\" successful"
    else
      rm -f $TMP_FILE
	  return 1
    fi
  else
    activity_log  "lget"  "$MODULE"  "$VERSION"  "failed" "broken URL: $1"
    return 1
  fi
}


plugin_register SOURCE_DOWNLOAD plugin_source_download_generic

--- NEW FILE: download-svn.plugin ---
#!/bin/bash
############################################################
#                                                          #
# download-svn.plugin - download SVN urls                  #
#                                                          #
############################################################
#                                                          #
# Copyright 2005 by Auke Kok under GPLv2                   #
#                                                          #
############################################################

# valid SVN urls are:
# svn://
# svn+http:// (will be transformed to http://)


plugin_source_download_svn() {
  # check if we can handle this URL format
  if [ "${1:0:6}" != "svn://" -a "${1:0:11}" != "svn+http://" ] ; then
    return 2
  fi
  debug_msg "plugin_source_needrefresh_svn($@)"

  if ! module_installed subversion ; then
    # full stop: we need to make sure the user sees this error:
    message "${PROBLEM_COLOR}! Cannot fetch SVN sources without \"subversion\" installed${DEFAULT_COLOR}"
    exit 1
  fi

  SVN_URL=$(echo $1 | cut -d: -f1-2)
  SVN_DIR=$(echo $1 | cut -d: -f3)
  # translate svn+http urls:
  if [ "${SVN_URL:0:11}" == "svn+http://" ]; then
    SVN_URL="http://${SVN_URL:11}"
  fi

  message  "${MESSAGE_COLOR}Downloading SVN module for" \
 	   "module ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"

  mk_source_dir $TMPDIR/$MODULE-$VERSION
  cd $TMPDIR/$MODULE-$VERSION

  if [ -f "$2" ] ; then
    verbose_msg "Extracting local SVN copy"
    # unpacking in last component dir of $SVN_DIR
    CD=$(pwd -P)
    if ! tar xjf $2 ; then
      message "${PROBLEM_COLOR}Warning: bad local SVN copy, checking out fresh SVN copy${DEFAULT_COLOR}"
      
      rm_source_dir $TMPDIR/$MODULE-$VERSION
      mk_source_dir $TMPDIR/$MODULE-$VERSION
    fi
    cd $CD
  fi

  NUM_RETRY=${NUM_RETRY:-5}
  if [ "$NUM_RETRY" -eq 0 ]; then
      NUM_RETRY=1000
  fi

  for (( TRY=1 ; $TRY<$NUM_RETRY+1 ; TRY++ )) ; do
    if [ -d "${SVN_DIR}/.svn" ] ; then
      cd ${SVN_DIR}
      verbose_msg "[${TRY}] svn up"
      svn up && GOT_SVN="yes" 
      cd ${CD}
    else
      verbose_msg "[${TRY}] svn co $SVN_URL $SVN_DIR"
      svn co $SVN_URL $SVN_DIR && GOT_SVN="yes"
    fi

    if [ "$?" == "0" ] ; then
      break
    fi

    sleep 2
  done
  
  if [ "$GOT_SVN" == "yes" ] ; then
    message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$2${DEFAULT_COLOR}"
    # pack in last component dir of $SVN_DIR
    tar cjf $2 $SVN_DIR
  else
    activity_log "lget"  "$MODULE"  "$VERSION"  "failed" "Could not get $1"
  fi

  cd $TMPDIR
  rm_source_dir $TMPDIR/$MODULE-$VERSION

}


plugin_source_needrefresh_svn() {
  # check if we can handle this URL format
  if [ "${1:0:6}" != "svn://" -a "${1:0:11}" != "svn+http://" ] ; then
    return 2
  fi
  debug_msg "plugin_source_needrefresh_svn($@)"

  if [ ! -f $2 ]; then
    return 0
  fi

  SVN_THRESHOLD=${SVN_THRESHOLD:-10}
  if (( "SVN_THRESHOLD" > 0 )) ; then
	if [ "$(find $2 -amin +$SVN_THRESHOLD)" == "$2" ] ; then
      # it is older:
	  return 0
	else
      verbose_msg "SVN update not required for \"$2\" (less than $SVN_THRESHOLD mins old)"
      # now we can send a FAIL so the next plugins are skipped:
	  return 1
    fi
  else
    # always return true if threshhold is zero
    return 0
  fi
}


plugin_register SOURCE_DOWNLOAD plugin_source_download_svn
plugin_register SOURCE_NEEDREFRESH plugin_source_needrefresh_svn




More information about the Lunar-commits mailing list