Script
#A prototype for a "migration wizard". #TODO: Make it safer, trap interrupts, more checks, etc.
set -e
winroot= docroot= sysroot= winuser= tempbookmarks=mktemp bookmarks=$HOME/.mozilla/firefox/*.default/bookmarks.html
#Import one folder of bookmarks (recursively for nested folders) and write it to tempfile import_bookmark_level() {
echo "<DT><H3>basename "$1"</H3>" >> $tempbookmarks echo "<DL><p>" >> $tempbookmarks #Loop through subdirectories find "$1" -maxdepth 1 -mindepth 1 -type d | \ while read i do
- import_bookmark_level "$i/"
bmhref=grep "^URL=" "$i" | sed 's|URL=||' | sed 's/.$//' bmname=basename "$i" .url echo "<DT><A HREF=\"$bmhref\">$bmname</A>" >> $tempbookmarks
echo "</DL><p>" >> $tempbookmarks
}
#Import all bookmarks from IE import_bookmarks() {
if grep firefox`" then
- zenity --error --text 'Firefox is open! Please close it and restart this program!' exit 1
- favorites="$docroot/$winuser/Favorites/" import_bookmark_level "$favorites"
}
#Find out which Windows user we are ask_user() {
while -z "$winuser" do
winuser=ls "$docroot" | sed '/All Users\|Default User\|LocalService\|NetworkService/d' | zenity --list --column User --text "Migration Wizard has found these users. Select one:" if [[ -n echo "$winuser" | grep '|' || -z "$winuser" ]] then
- zenity --error --text 'Please select -one- user!' unset winuser
}
#Find where the Windows drive is mounted find_winroot() {
- for i in /media/* do
tmp=find $i -maxdepth 1 -iname "documents and settings" if -n "$tmp" then
- winroot=$i docroot=$tmp
sysroot=find $i -maxdepth 1 -iname "windows" echo "Found Windows drive at $winroot..."
- winroot=$i docroot=$tmp
}
find_winroot
ask_user
#Inserts our imported bookmarks into Firefox's bookmark file cat $bookmarks | sed '$d' > $tempbookmarks import_bookmarks echo "</DL><p>" >> $tempbookmarks
mv $tempbookmarks $bookmarks