All pastes #186112 Raw Edit

Miscellany

public text v1 · immutable
#186112 ·published 2006-09-29 15:32 UTC
rendered paste body
#!/bin/bash


##This a script for the translators to be able to check their translated .po files
##when written. It will take their .po file and make sure it is looking right, and 
##install it on their system.


##Test to make sure there is an argument when the script is called.


if [ $# != 1 ]
	then
	echo "Usage: test-po <filename.po>; "
	echo "One po file at a time please"
	echo " write the .po filename after the program"
	exit 1
fi



###Testing to see if the .po file exists and is a valid and complete file with 
###no errors


###Declaring some variables

arg=$1				### the first argument on this script		
workingdir=`pwd`		### the dir we are working on the po file from
rpmdir=/usr/src/redhat/ 	### what do you THINK this is, bubba?



if [ -r "$arg" ] && msgfmt -c "$arg" -o /dev/null
	then
	echo " $arg is a valid po file"
	else
	echo "$arg is NOT a valid po file, please check and correct it";
	exit 1
fi


###Now, if the po file has been verified as ok, then we continue...
### Do we have the translator's language source rpm?

#This will give us JUST the translator's locale:

lang=`echo $LANG | awk -F_ '{print $1}'`

#to get the source rpm, we check the translator's home dir setup for that purpose:
#a dir called trans-rpm

ls ~/trans-rpm/ 2> /dev/null | grep $lang > /dev/null 

if [ $? != 0 ]
	then 
	echo "The RPM isnt found, better call shina to come and suffer oh!"
	exit 1
fi


##Now to install the rpm 

tarname=`ls ${rpmdir}/SOURCES/ | grep $lang`		###Appropriate translation tarball, after installing

tardir=`echo ${tarname%.tar.gz}`			###Appropriate extracted tar dir

transpec=`ls ${rpmdir}/SPECS/ | grep $lang`	   	##Appropriate translator's spec file


###Installiing the source rpm
rpm -ivh `ls ~/trans-rpm/* | grep $lang`


cd $rpmdir 
ls SOURCES/ 2> /dev/null | grep $lang > /dev/null

if [ $? != 0 ] 
	then 
	echo "no appropriate tar.gz file, quitting"
	exit 1
	
	else echo "extracting translations tar.gz file"
	tar -zxvf $tarname
	echo "removing the tar.gz"

	
	cd ${rpmdir}/SOURCES/
	rm -fr $tarname
	cd $workdir
	cp -f $arg ${rpmdir}/SOURCES/${tardir}/ > /dev/null ##copying our new po file to the extracted source dir
	

if [ $? != 0 ]
	then
	echo "could not copy $arg to the tar dir, script failed"
	exit 1
if


## Repacking the tar.gz...
	echo "repacking the $tarname file..."
cd ${rpmdir}/SOURCES/
tar -cvzf $tarname  $tardir
rm -fr $tardir

##Creating new RPM file
	echo "writing new rpm file..."
	rpmbuild -ba ${rpmdir}/SPECS/${transpec}