git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1561 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/sh
 | |
| # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
 | |
| 
 | |
| # Opens the specified table in the users editor and writes changes back to the db
 | |
| 
 | |
| function cexit {
 | |
|   if [ -d /tmp/tabedit.$$ ]; then
 | |
|     rm -rf /tmp/tabedit.$$;
 | |
|   fi
 | |
|   exit
 | |
| }
 | |
| trap cexit 2 15
 | |
| 
 | |
| TABLE=$1
 | |
| if [ -z "$TABEDITOR" ]; then
 | |
|   TABEDITOR=$EDITOR
 | |
| fi
 | |
| if [ -z "$TABEDITOR" ]; then
 | |
|   #echo "WARNING: Define TABEDITOR or EDITOR environment variable before running this command"
 | |
|   TABEDITOR=vi
 | |
| fi
 | |
| if [ -z "$TABLE" -o "$TABLE" = "-?" -o "$TABLE" = "-h" -o "$TABLE" = "--help" ]; then
 | |
|     echo "Usage: tabedit <tablename>";
 | |
|     echo "       tabedit [-? | -h | --help]";
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| # Dump the table to a temporary file
 | |
| mkdir -p /tmp/tabedit.$$/
 | |
| xcatclientnnr tabdump $TABLE > /tmp/tabedit.$$/$TABLE.csv
 | |
| 
 | |
| # Save the checksum to see if it actually changes..
 | |
| if [ `uname` = "AIX" ]; then
 | |
| 	SUMPROGRAM=sum
 | |
| else
 | |
| 	SUMPROGRAM=md5sum
 | |
| fi
 | |
| SUM=`$SUMPROGRAM /tmp/tabedit.$$/$TABLE.csv`
 | |
| 
 | |
| # Edit the file, then check it
 | |
| EXIT=0
 | |
| while [ $EXIT -eq 0 ]; do
 | |
|   cd /tmp/tabedit.$$
 | |
|   "$TABEDITOR" $TABLE.csv
 | |
|   cd - >/dev/null
 | |
|   NEWSUM=`$SUMPROGRAM /tmp/tabedit.$$/$TABLE.csv`
 | |
|   if [ "$NEWSUM" == "$SUM" ]; then
 | |
|     echo "No file modifications detected, not restoring."
 | |
|     break;
 | |
|   fi
 | |
|   if `dirname $0`/tabrestore /tmp/tabedit.$$/$TABLE.csv; then
 | |
|     break;
 | |
|   else
 | |
|     echo "Above errors occured, hit enter to edit, or ctrl-c to abort"
 | |
|     read JNK
 | |
|   fi
 | |
| done
 | |
| cexit
 | |
| 
 |