#!/bin/bash
# File: src-dir-to-html.sh v.1.3.0 docs at the end
umask 000 ;
# print the commands
set -x
# print each input line as well
set -v
# exit the script if any statement returns a non-true return value. gotcha !!!
# set -e
# set the variables from the $0.hostname.conf file which has ini like syntax
setVars(){
export PATH=/cygdrive/c/cygwin/bin/:$PATH
MyDir=`dirname $(readlink -f $0)`
cd "$MyDir"
# echo go up 4 times
for i in {1..5} ; do cd .. ; done ;
#echo print the pwd
ProductBaseDir=`pwd`
echo "ProductBaseDir is $ProductBaseDir \n\n"
Tmp="$MyDir/tmp/tmp.$$"
mkdir -p $Tmp #create the tmp dir if it does not exist
( set -o posix ; set ) >$Tmp/variables.before
MyName=`basename $0`
IniFile="$MyDir/$MyName.`hostname`.conf"
IniSection=MainSection
LogFile="$MyDir/$MyName.log"
# get the machine / host specific configuration
parseIniFile
#source $0
( set -o posix ; set ) >$Tmp/variables.after
wlog " Using the following vars :"
cmd="comm --nocheck-order -3 $Tmp/variables.before $Tmp/variables.after"
runCmdAndLog $cmd
rm -f $Tmp/variables.before $Tmp/variables.after
rm -f $Tmp/variables.before $Tmp/variables.before
}
#eof function setVars
# parse the ini like $0.hostname.conf and set the variables
parseIniFile(){
eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
-e 's/;.*$//' \
-e 's/[[:space:]]*$//' \
-e 's/^[[:space:]]*//' \
-e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
< $IniFile \
| sed -n -e "/^\[$IniSection\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`
}
#eof function parseIniFile
# run a command and log the call and its output to the LogFile
# usage: runCmdAndLog $cmd
runCmdAndLog(){
cmd="$*" ;
wlog " DEBUG running cmd : \"$cmd\""
Msg=$($cmd 2>&1)
[ $? -eq 0 ] || wlog "ERROR : Failed to run the following command \"$cmd\" with the following output \"$Msg\" !!!"
wlog " DEBUG : cmdoutput : \"$Msg\""
}
#eof function runCmdAndLog
# run a command on failure exit with message
# usage: runCmdOrExit $cmd
runCmdOrExit(){
cmd="$*" ;
wlog " DEBUG running cmd : \"$cmd\""
Msg=$($cmd 2>&1)
# if error occured during the execution exit with error
[ $? -eq 0 ] || Exit "ERROR : FATAL : Failed to run the following command \"$cmd\" with the following output \"$Msg\" !!!"
#if no error occured just log the message
wlog " DEBUG : cmdoutput : \"$Msg\""
}
#eof function runCmdOrExit
# echo pass params and print them to a log file
wlog(){
# check terminal if exists echo
test -t 1 && echo "`date +%Y.%m.%d-%H:%M:%S` [$$] $*"
# check LogFile and
test -z $LogFile || {
echo "`date +%Y.%m.%d-%H:%M:%S` [$$] $*" >> $LogFile
} #eof test
}
# eof function wlog
replicateSrcDirStructure(){
# go to the common root
cd $ProductVersionDir
# replicate the folder structure
find sfw -type d -exec mkdir -p docs/html/src/{} \;
}
#eof func replicateSrcDirStructure
createSfwSrcDocs(){
wlog " DEBUG START createSfwSrcDocs"
cd "$ProductVersionDir"
# foreach src file create its html file into the src html dir
find "sfw" -type f -exec perl $CodeToHtml {} docs/html/src/{}.html \;
cmd="find $ProductVersionDir/docs/html/src/perl/ -type f"
runCmdAndLog $cmd
wlog " DEBUG STOP createSfwSrcDocs"
}
#eof wlog " DEBUG createSfwSrcDocs"
# exit with passed status and message
Exit(){
ExitStatus=0
case $1 in
[0-9]) ExitStatus="$1"; shift 1;;
esac
Msg="$*"
test "$ExitStatus" = "0" || Msg=" ERROR: $Msg"
wlog " $Msg"
exit $ExitStatus
}
#eof function Exit
# the main function called
main(){
setVars
replicateSrcDirStructure
createSfwSrcDocs
Exit 0 "created the docs"
}
#eof function main
# Action !!!
main
#
# Purpose:
# to produce the html files our of the source files from the sfw dir into a replicated
# docs/html/src/sfw dir
# features:
# - prints the set in the script variables
# - separation of host specific vars into $0.`hostname`.conf file
# - wlog function for both xterm and log file printing
# - for loop examples with head removal and inline find and replace
#
# Requirements
# - cygwin , perl , sh , code2html by
# -
#
# VersionHistory:
# 1.4.0 --- 2012-07-24 17:33:29 --- ysg --- Initial creation of src-dir-to-html.sh
# 1.3.0 --- 2012-05-20 18:48:08 --- ysg --- replacing cmd with error output
# 1.2.4 --- 2012-05-02 20:41:11 --- ysg --- added for loop with pipes
# 1.1.0 --- ysg --- add runcmd with erro
# 1.0.0 --- ysg --- Initial creation of sh_stub
#
# EOF file:src-dir-to-html.sh
syntax highlighted by Code2HTML, v. 0.9.1
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!