#!/bin/bash

#
# Convert Opera-bookmarks to mozilla-bookmarks
# (c) Mark Ulrich, 2006
# License: LGPL
#
# Versions used: Opera 9 , Seamonkey 1.0
#

cat opera6.adr | sed -e "s/^\t*//" -e "s/^#FOLDER/MUMARKERFOLDERX/"  -e "s/^-/MUMARKERFOLDERCLOSE/" -e "s/^URL=/MUMARKERURL/" -e "s/^NAME=/MUMARKERNAME/" -e "s/^[^MUMARKER].*//" |grep "MUMARKER" >1.txt



rm -f 2.txt
touch 2.txt

cat 1.txt | while read a;do

check=`echo "$a" | grep MUMARKERFOLDERCLOSE`
if [ "$check" != "" ];then
echo "    </DL><p>">> 2.txt
else

check=`echo "$a" | grep MUMARKERFOLDERX`
if [ "$check" == "" ];then
read b
echo $a$b  >> 2.txt
else
read b
echo "    <DT><H3>$b</H3>" | sed "s/MUMARKERNAME//">> 2.txt
echo "    <DL><p>">> 2.txt
fi
fi
done 



rm -f 1.txt
rm -f 3.txt
touch 3.txt

#echo "    <DT><H3>Opera-bookmarks</H3>"> 3.txt
#echo "    <DL><p>">> 3.txt

cat 2.txt | sed -e "s/MUMARKERNAME/        <DT><A HREF=\"/" -e "s/MUMARKERURL/\">/" -e "s/$/<\/a>/"   >>3.txt
#echo "    </DL><p>">> 3.txt

cat `find /root/.mozilla/ -name bookmarks.html` | grep -v "^</DL><p>" > bookmarks.html

cat 3.txt >> bookmarks.html
echo "</DL><p>" >> bookmarks.html

rm -f 2.txt
rm -f 3.txt

echo "

Finished conversion.
Now copy bookmarks.html to
`find /root/.mozilla/ -name bookmarks.html`

"

