'
sectionAppend[2]=''
tokenStart[2]=''
tokenEnd[2]='
'
sedScript[2]='
s{<{\<{g
s{>{\>{g
s{&{\&{g
s{\[HOSTNAME\]:\[DEVICE\]:{\[HOSTNAME\]:\n \[DEVICE\]:{g
s!\*\*LAYOUT\*\*, \(.\)kvariant!\*\*LAYOUT\*\*,\n \1kvariant!
s{modelcode}=\*\*CODE\*\*{modelcode}=\n \*\*CODE\*\*{
/link:/{
s{\[{+{g
s{\]{_{g
s{link:\([^+]*\)+\([^_]*\)_{
\2{g
}
'
# Configuration for Clonezilla documentation section
name[3]=Clonezilla
webPage[3]='http://clonezilla.org/clonezilla-live/doc/99_Misc/00_live-initramfs-manual.doc'
startTAG[3]='Clonezilla live is based on'
endTAG[3]='root file system filesystem.squashfs.'
sectionPrepend[3]=''
sectionAppend[3]='
'
tokenStart[3]=''
tokenEnd[3]='
'
sedScript[3]='
s{
{{g
s{]*>{{g
s{{{g
s{<.tr>{{g
s{<.td[^>]*>{{g
s{You can refer to this ]*>\([^>]*\){You can refer to this \1{
1s{^{ {
'
##############################################################################
# funtion to make all happen
#
function updateContent(){
echo "Updating ${name[$1]} documentation"
# Fix varaibles for sed (sed syntax)
tokenEndReplace=`echo "${tokenEnd[$1]}" | sed 's|/|\\/|'`
tokenEnd=`echo "${tokenEnd[$1]}" | sed 's|/|\.|'`
# Download original web page/file
if [ -n "${webPage[$1]}" ];then
downloadFile $1
else
if [ ! -e /tmp/webPage.$$ ];then
downloadFile $1
fi
fi
echo -n " Adding web content to file... "
# Extract and format content from original page
# if startTAG[$1] is empty, just copy the page
# new content file: /tmp/tmp.$$
if [ -n "${startTAG[$1]}" ];then
sed -n "/${startTAG[$1]}/ , /${endTAG[$1]}/ p" /tmp/webPage.$$ | sed '
s{/[tT][aA][rR][gG][eE][tT]="[^"]"{{g
s{[aA] [hH][rR][eE][fF]={a target="_blank" href={g
s{/[tT][aA][rR][gG][eE][tT]="[^"]"{{g
s{target=_blank{{g
s{[aA] [hH][rR][eE][fF]={a target="_blank" href={g
' > /tmp/tmp.$$
else
cp /tmp/webPage.$$ /tmp/tmp.$$
fi
# Apply page specific sed script to new content
if [ -n "${sedScript[$1]}" ];then
echo "${sedScript[$1]}" > /tmp/sedScript.$$
sed -f /tmp/sedScript.$$ /tmp/tmp.$$ > /tmp/tmp-new.$$ && mv /tmp/tmp-new.$$ /tmp/tmp.$$
rm /tmp/sedScript.$$
fi
# Apply prepend text to new content
if [ -n "${sectionPrepend[$1]}" ];then
echo "${sectionPrepend[$1]}" > /tmp/tmp-new.$$
cat /tmp/tmp.$$ >> /tmp/tmp-new.$$
mv /tmp/tmp-new.$$ /tmp/tmp.$$
fi
# Applly append text to new content
if [ -n "${sectionAppend[$1]}" ];then
echo "${sectionAppend[$1]}" >> /tmp/tmp.$$
fi
# remove old content form current page
sed "/${tokenStart[$1]}/!b
:a
/"${tokenEnd}"/!{
N
ba
}
s[${tokenStart[$1]}.*${tokenEnd}[${tokenStart[$1]}\n${tokenEndReplace}[" boot-params.html > /tmp/page.$$
# insert new content to current page
if [ -n "$createTamplatePage" ];then
cp /tmp/page.$$ boot-params.html
else
sed "/${tokenStart[$1]}/r /tmp/tmp.$$" < /tmp/page.$$ > boot-params.html
fi
# clean up
rm /tmp/page.$$ /tmp/tmp.$$ /tmp/tmp-new.$$ 2>/dev/null
echo 'done'
}
##############################################################################
# funtion to download the original web page
#
function downloadFile(){
echo -n " Downloading web page... "
rm /tmp/webPage.$$ 2>/dev/null
wget -q "${webPage[$1]}" -O /tmp/webPage.$$ && echo 'done' || {
echo "
Error downloading original web page"
exit 1
}
}
##############################################################################
# funtion clean up things when exiting
#
function cleanUp(){
rm /tmp/webPage.$$
}
##############################################################################
#
# Script starts here
#
##############################################################################
# Go to working/ directory
cd ..
updateContent 0 || {
cleanUp;exit 1
}
updateContent 1 || {
cleanUp;exit 2
}
updateContent 2 || {
cleanUp;exit 3
}
updateContent 3 || {
cleanUp;exit 4
}
cleanUp
|