#! /bin/csh -f # DbRebuild, version 2.4 (110299) # Automated process to import Edge data # # Created 23 Feb 99 by Justin Mercier # jmercier@autometric.com # # Various routines borrowed from Mark T. Sullivan and Bill Kelanic # # Version *.1 - updates RRD routine to skip files with pre-existing RRDs # Version 2.0 - Skipped in accordance with EDGE version policies # Version 2.1 - Major rewrite to fix loop blowout due to word length in {var} # Renamed to DbRebuild because it sounds cooler # Version 2.2 - Fixed filename integrity check # Version 2.3 - Fixed BIGLOOP structure ( skips space correction for RRD/PIXMAP routines ) # Version 2.4 - Fixed temp cleanup and added data mode correction #Check usage if ( $#argv < 1 ) then echo "Path to data not set. (Usage: $0 startpath [routine {MDA|RRD|PIXMAP}])" exit 1 else if !( -e $1 ) then echo "Path does not exist : $1" exit 1 else set PATH=$1 endif #Source EPF env cd /usr/Edge/importUtil source ../config/environment #Check for explicit routine call if ( $#argv < 2 ) then #No routine specified, so do nothing and continue echo >& /dev/null else if (( $argv[2] == "RRD")||( $argv[2] == "PIXMAP" )) then # Skip MDA pre-routine and move ahead set ROUTINE=$argv[2] goto BIGLOOP else if ( $argv[2] != "MDA" ) then echo "Invalid routine. (Usage: $0 startpath [ routine {MDA|RRD|PIXMAP} ])" exit 1 else # If we've gotten this far, argv[2] must be MDA, so we'll just continue set ROUTINE="MDA" endif endif # MDA pre-routine - backup database and export tables # Check for database and option to backout tables clear # Check for database if !( -e /usr/Edge/database/eweVersion ) then echo "There does not appear to be an Edge database in /usr/Edge/database." echo "Run Edge to create a distribution database and then try again." exit 1 endif if ( -e /usr/Edge/database.backup ) then echo "Backing up database...." cp -r /usr/Edge/database /usr/Edge/database.`date | awk '{ print $2$3 }'`.`date | awk '{ print $4 }' | sed -e 's#:##g'`.backup else echo "Backing up database...." cp -r /usr/Edge/database /usr/Edge/database.`date | awk '{ print $2$3 }'`.`date | awk '{ print $4 }' | sed -e 's#:##g'`.backup endif clear echo "**************************************************************************" echo "Unless you are running this on an add-on file-system (i.e. new data disk)," echo "it is recommended that you have a clean set of image,elev, and map tables" echo "to prevent duplicate database entries. In addition to creating a clone of" echo "your current database, this script can backup these tables and purge them" echo "for a complete rebuild." echo "**************************************************************************" echo echo -n "Do you wish to export and purge your tables? (y/n)" set PURGE=$< clear if (( $PURGE == y )||( $PURGE == Y )) then set eweEMPTY cd ../utilities #Create Export filenames and prevent overwrite #Determine Image Export file if ( -e Image.exp ) then set APPEND=2 while ( -e Image$APPEND.exp ) set APPEND = `expr $APPEND + 1` end set IMAGEEXP=Image$APPEND.exp else set IMAGEEXP=Image.exp endif #Determine Elev Export file if ( -e Elev.exp ) then set APPEND=2 while ( -e Elev$APPEND.exp ) set APPEND = `expr $APPEND + 1` end set ELEVEXP=Elev$APPEND.exp else set ELEVEXP=Elev.exp endif #Determine Map Export File if ( -e Map.exp ) then set APPEND=2 while ( -e Map$APPEND.exp ) set APPEND = `expr $APPEND + 1` end set MAPEXP=Map$APPEND.exp else set MAPEXP=Map.exp endif #Export the tables echo "Exporting Tables..." if { ./EdhExport -p /usr/Edge/database -t Image -f $IMAGEEXP } then echo "Exported Image table to $cwd/$IMAGEEXP" else echo "Error exporting Image table. Exiting..." exit 1 endif if { ./EdhExport -p /usr/Edge/database -t Elevation -f $ELEVEXP } then echo "Exported Elevation table tp $cwd/$ELEVEXP" else echo "Error exporting Elevation table. Exiting ..." exit 1 endif if { ./EdhExport -p /usr/Edge/database -t Map -f $MAPEXP } then echo "Exported Map table to $cwd/$MAPEXP" else echo "Error exporting Map table. Exiting..." exit 1 endif #Empty the tables #Image Table echo echo "Purging Tables..." if { ./EdhEmptyTable -p /usr/Edge/database -t Image } then echo >& /dev/null else echo "Error purging Image table. Exiting..." exit 1 endif #Elev Table if { ./EdhEmptyTable -p /usr/Edge/database -t Elevation } then echo >& /dev/null else echo "Error purging Elevation table. Exiting..." exit 1 endif #Map Table if { ./EdhEmptyTable -p /usr/Edge/database -t Map } then echo >& /dev/null else echo "Error purging Map table. Exiting..." exit 1 endif echo echo " ********************************" echo "****** Table export and purge complete. ******" echo " ********************************" echo -n "Press return to continue or X to exit:" set EXIT=$< if (( $EXIT == X )||( $EXIT == x )) then exit 0 endif else echo "?????????????????????????????????????????????" echo -n "Table backup/purge aborted. Continue? (y/n)" set CONTINUE=$< if (( $CONTINUE != y )||( $CONTINUE != Y )) then goto BIGLOOP else echo "Exiting due to user input." exit 1 endif endif # Mount directory which contains the required toys cd /usr/Edge/importUtil # Loop which does the major work and is the bulk of the 2.1 rewrite. Thanks to Brad Beach for the debugging help. BIGLOOP: clear echo '////// Building data directory index \\\\\\' set DIRS=`find $PATH -type d` foreach ACTDIR ( $DIRS ) # Check for routine call and act accordingly if ( $?ROUTINE ) then if ( $ROUTINE != "MDA" ) then goto $ROUTINE endif endif MDA: cd $ACTDIR echo echo "---- Checking for Edge Data files in $ACTDIR...." ls *.mda >&! dbr.filelist if ( "`head -1 dbr.filelist`" != "No match" ) then unset CANDIDATE set CANDIDATE=`ls *.mda` if ( "$CANDIDATE" != "" ) then foreach MDA ( $CANDIDATE ) set MDABASE="$MDA:r" set TYPE=`head -1 $MDA` if ( $TYPE == 1 ) then set TABLE="Image" else if ( $TYPE == 2 ) then set TABLE="Map" else if ( $TYPE == 4 ) then set TABLE="Elevation" else echo "Cannot determine format for $MDA, skipping...." goto ENDMDALOOP endif cd /usr/Edge/importUtil ./Mda2Db -p /usr/Edge/database -t $TABLE -i $ACTDIR/$MDABASE cd $ACTDIR # Way out for skipped mda's without breaking loop ENDMDALOOP: end endif endif # Check for routine call and act accordingly if ( $?ROUTINE ) then if ( $ROUTINE == "MDA" ) then # Skip the rest of the loop and process next dir goto ENDLOOP endif endif RRD: cd $ACTDIR echo echo "++++ Checking for RRDs in $ACTDIR..." echo ls *.mda >&! dbr.filelist if ( "`head -1 dbr.filelist`" != "No match" ) then unset CANDIDATE set CANDIDATE=`ls *.mda` if ( "$CANDIDATE" != "" ) then foreach RRD ( $CANDIDATE ) set RRDBASE=$RRD:r set TYPE=`head -1 $RRD` if ( $TYPE == 1 ) then set TABLE="image" else if ( $TYPE == 2 ) then # EdgeCreateRRd treats Images and Maps the same. Not a mistake! set TABLE="image" else if ( $TYPE == 4 ) then set TABLE="ele" else echo "Cannot determine format for $RRD, skipping...." goto ENDRRDLOOP endif set RRDEXIST="`ls $RRDBASE.rrd001* | grep rrd`" if ( "$RRDEXIST" == "" ) then echo " Creating RRDs for $RRDBASE ***************" cd /usr/Edge/importUtil ./EdgeCreateRRD $TABLE $ACTDIR/$RRDBASE cd $ACTDIR else echo "RRDs exist for $RRDBASE. Skipping..." endif # Way out for skipped rrd's without breaking loop ENDRRDLOOP: end endif endif # Check for routine call and act accordingly if ( $?ROUTINE ) then if ( $ROUTINE == "RRD" ) then # Skip the rest of the loop and process next dir goto ENDLOOP endif endif PIXMAP: cd $ACTDIR echo echo '<><> Checking for thumbnails and creating as needed ' unset CANDIDATE ls *.mda >&! dbr.filelist if ( "`head -1 dbr.filelist`" != "No match" ) then set CANDIDATE=`ls *.mda` foreach PIX ( $CANDIDATE ) set TYPE=`head -1 $PIX` set PIXBASE=$PIX:r if (( $TYPE == 1 )||( $TYPE == 2 )) then echo ; echo "Creating Pixmap for $PIXBASE..." echo cd /usr/Edge/importUtil ./EdgeCreatePixmap $ACTDIR/$PIXBASE endif end endif ENDLOOP: end clear echo "Setting data file permissions to root 755 (for restricted write) ......" chmod -R 755 $PATH echo echo "Setting data directory permissions to 777 (for global write) ......" find $PATH -type d -exec chmod 777 {} \; >& /dev/null echo echo "Cleaning temp files...." find $PATH -name dbr.filelist -exec rm {} \; >& /dev/null if (( $?eweEMPTY )&&( $PATH != /usr/Edge/data )) then clear echo "???????????????????????????????????????????????????????" echo -n "Would you like to include Edge distribution data? (y/n)" set DIST=$< if (( $DIST == y )||( $DIST == Y )) then set PATH=/usr/Edge/data goto BIGLOOP endif endif echo;echo if ( $?ROUTINE ) then echo "$ROUTINE processing complete." else echo "Database rebuild on $PATH complete." endif exit 0