#!/bin/bash
## bookdiff -- a script for reconciling forked mozilla/firefox bookmark files
## The URLs in the two bookmark files are compared, and uniq URLs are sorted
## and written to a file bookdiff.html
if [ x$2 = x ] || [ x$3 != x ]
then echo
echo ' bookdiff- a script for reconciling forked mozilla/firefox bookmark files'
echo ' Usage: bookdiff [path/]bookmarkfile1 [path/]bookmarkfile2'
echo ' BLANK SPACES IN FILE NAMES ARE *EVIL* AND NOT ALLOWED HERE!'
echo
exit 0
fi
## These strings must be exported because they will be used in a sub-shell
export file1=$1
export file2=$2
## Declare a function to parse a list of unique URLs into a list of proper
## html anchor tags complete with line breaks.
parser() ## When called this function reads a temp file for input.
{
while read urlmark
do
if echo $urlmark |grep file:/// >/dev/null
then hostmark=$urlmark
else hostmark=$(echo $urlmark | cut -d\/ -f 3)
fi
if grep $urlmark $file1 >/dev/null 2>&1
then filename=$file1
else filename=$file2
fi
echo $filename -- \$hostmark '
' >>bookmarks.sort3
done
}
## Cut out all of the URLs from each file, and save a single instance
## of each one, from each file
grep "HREF=" $file1 | cut -d \" -f 2 | sort| uniq >>bookmarks.sort1
grep "HREF=" $file2 | cut -d \" -f 2 | sort| uniq >>bookmarks.sort1
## This step separates out the URLs found in either one of, but not both files.
sort bookmarks.sort1 | uniq -u >bookmarks.sort2
parser ' >bookdiff.html
grep $file1 bookmarks.sort3 >>bookdiff.html
echo '
' >>bookdiff.html
echo '
' >>bookdiff.html
grep $file2 bookmarks.sort3 >>bookdiff.html
echo '