#!/bin/sh # # @(#)$Id: importDirSort.sh,v 1.4 2001/10/09 16:33:46 sander Exp $ # # Script to import a tree of components into the Contelligent System. # Requires environment variable 'CONTELLIGENT_BASEURL' to be set. # The order of the file is given by a number in the filename. filenames # must be of the form ..xml where # name - MUST NOT contain any "." (dots) # number - is a number (what a surprise) # # e.g. files in a directory a.10.xml b.30.xml c.15.xml d.100.xml will be imported # in the order a c b d # # this function can be used to import a tree where newer versions of subtrees are in # different files. # # Author: Jan Stoevesand # based on importDir.sh scriptName=`basename $0` bindir=`dirname "$0"` test -r "$bindir/procs.sh" || { echo "? $scriptname"": internal error - cannot read \`$bindir/procs.sh'." >&2; exit 1; } . "$bindir/procs.sh" # read external funtions makeabs bindir # make 'bindir' contain an absolute path printUsage() { echo "usage: $scriptName " echo " - the directory containing the xml files to import (recursivly)" echo "" echo "Note that the environment variable 'CONTELLIGENT_BASEURL' must contain" echo "the URL of a (running) Contelligent server." } #------------------------------------------------------------------------------ # # defaults # wget_opts="-nv --spider" # --spider: don't download anything. importURL="${CONTELLIGENT_BASEURL}/system/import.jsp?FILENAME" if [ "$1" = "" -o "$2" = "" -o "$CONTELLIGENT_BASEURL" = "" ]; then printUsage>&2 exit 1 fi echo $1 echo Version $2 files="*.$2.*.xml" searchstring="*.$2.*.xml" # # now add all .xml files from subdirs: files=`find $1 -type f -name "*.$2.*.import.xml" -print | sort -r -t. -k 3n` # files="`find $2 -type f -name '*.import.xml' -print | sort -r -t . -k 4n`" # files="`find $2 -type f -name $searchstring -print | sort -r -t . -k 2n`" # files="`find $2 -type f`" # $files = "echo $files | sort -r -t . -k 4n" echo $files # # let's go ... # for file in $files; do makeabs file # make 'file' contain an absolute path echo "importing '$file' ..." wget $wget_opts "${importURL}=$file" rc=$? if [ $rc -ne 0 ]; then echo "error while importing file '$file' !">&2 exit 2 fi done