Script

Differences between revisions 2 and 5 (spanning 3 versions)
Revision 2 as of 2006-05-17 06:17:13
Size: 2201
Editor: adsl-75-3-1-183
Comment:
Revision 5 as of 2008-08-06 16:29:13
Size: 4040
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
#A prototype for a "migration wizard".
Line 6: Line 5:
Line 14: Line 12:
tempbookmarks=`mktemp` tempbookmarks=
Line 16: Line 14:
Line 20: Line 17:
 echo "<DT><H3>`basename "$1"`</H3>" >> $tempbookmarks
 echo "<DL><p>" >> $tempbookmarks

 #Loop through subdirectories
 #Loop through subdirectories first
Line 27: Line 21:
  echo "<DT><H3>`basename "$i"`</H3>" >> $tempbookmarks
  echo "<DL><p>" >> $tempbookmarks
Line 28: Line 24:
  echo "</DL><p>" >> $tempbookmarks
Line 38: Line 35:
   echo "</DL><p>" >> $tempbookmarks
Line 49: Line 44:
  favorites="$docroot/$winuser/Favorites/"
  import_bookmark_level "$favorites"
  #Inserts our imported bookmarks into Firefox's bookmark file
  tempbookmarks=`mktemp`
  
  #Takes everything but the last line
  cat $bookmarks | sed '$d' > $tempbookmarks
  
  #Inserts new bookmarks
  echo "<DT><H3>Imported IE Favorites</H3>" >> $tempbookmarks
  echo "<DL><p>" >> $tempbookmarks
  import_bookmark_level "$docroot/$winuser/Favorites/"
  echo "</DL><p>" >> $tempbookmarks
  
  #Finish it off
  echo "</DL><p>" >> $tempbookmarks
  
  #Atomic baby
  mv $tempbookmarks $bookmarks
Line 52: Line 62:
}

import_firefox_bookmarks() {
 if [[ -n "`ps -A | grep firefox`" ]]
 then
  zenity --error --text 'Firefox is open! Please close it and restart this program!'
  exit 1
 else
  #Inserts our imported bookmarks into Firefox's bookmark file
  tempbookmarks=`mktemp`
  profile=`cat "$docroot/$winuser/Application Data/Mozilla/Firefox/profiles.ini" | grep Path= | sed 's/Path=//' | sed 's/.$//'`

  #Takes evverything but the last line
  cat $bookmarks | sed '$d' > $tempbookmarks
  
  #Inserts new bookmarks
  cat "$docroot/$winuser/Application Data/Mozilla/Firefox/$profile/bookmarks.html" | sed '1,/<TITLE>/d' | sed '1 s/Bookmarks/Imported Firefox Bookmarks/' | sed '1 s/H1/H3/g' | sed 's/ID="*"//' | sed 's/PERSONAL_TOOLBAR_FOLDER="true"//' >> $tempbookmarks
  
  #Finish it off
  echo "</DL><p>" >> $tempbookmarks
  
  #Atomic baby
  mv $tempbookmarks $bookmarks
 fi
}

#Find out what the user wants to import
ask_import() {
 zenity --list --checklist --column Import? --column Settings --text "Choose settings to import:" TRUE "IE Favorites" TRUE "Firefox Bookmarks" TRUE Wallpaper
Line 86: Line 125:
#Inserts our imported bookmarks into Firefox's bookmark file
cat $bookmarks | sed '$d' > $tempbookmarks
import_bookmarks
echo "</DL><p>" >> $tempbookmarks
import=`ask_import`
Line 91: Line 127:
mv $tempbookmarks $bookmarks if [[ -n `echo $import | grep "IE Favorites"` ]]
then
 import_bookmarks
fi

if [[ -n `echo $import | grep "Firefox Bookmarks"` ]]
then
 import_firefox_bookmarks
fi

if [[ -n `echo $import | grep Wallpaper` ]]
then
 mkdir -p "$HOME/Pictures/Wallpapers/"
 cp "$docroot/$winuser/Local Settings/Application Data/Microsoft/Wallpaper1.bmp" "$HOME/Pictures/Wallpapers/Imported.bmp"
 gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$HOME/Pictures/Wallpapers/Imported.bmp"
fi

#TODO: Make it safer, trap interrupts, more checks, etc.

set -e

winroot=
docroot=
sysroot=
winuser=
tempbookmarks=
bookmarks=$HOME/.mozilla/firefox/*.default/bookmarks.html

#Import one folder of bookmarks (recursively for nested folders) and write it to tempfile
import_bookmark_level() {
        #Loop through subdirectories first
        find "$1" -maxdepth 1 -mindepth 1 -type d | \
        while read i
        do
                echo "<DT><H3>`basename "$i"`</H3>" >> $tempbookmarks
                echo "<DL><p>" >> $tempbookmarks
                import_bookmark_level "$i/"
                echo "</DL><p>" >> $tempbookmarks
        done

        #Loop through .url files (where IE stores bookmarks)
        find "$1" -maxdepth 1 -name "*.url" | \
        while read i
        do
                bmhref=`grep "^URL=" "$i" | sed 's|URL=||' | sed 's/.$//'`
                bmname=`basename "$i" .url`
                echo "<DT><A HREF=\"$bmhref\">$bmname</A>" >> $tempbookmarks
        done
}

#Import all bookmarks from IE
import_bookmarks() {
        if [[ -n "`ps -A | grep firefox`" ]]
        then
                zenity --error --text 'Firefox is open! Please close it and restart this program!'
                exit 1
        else
                #Inserts our imported bookmarks into Firefox's bookmark file
                tempbookmarks=`mktemp`
                
                #Takes everything but the last line
                cat $bookmarks | sed '$d' > $tempbookmarks
                
                #Inserts new bookmarks
                echo "<DT><H3>Imported IE Favorites</H3>" >> $tempbookmarks
                echo "<DL><p>" >> $tempbookmarks
                import_bookmark_level "$docroot/$winuser/Favorites/"
                echo "</DL><p>" >> $tempbookmarks
                
                #Finish it off
                echo "</DL><p>" >> $tempbookmarks
                
                #Atomic baby
                mv $tempbookmarks $bookmarks
        fi
}

import_firefox_bookmarks() {
        if [[ -n "`ps -A | grep firefox`" ]]
        then
                zenity --error --text 'Firefox is open! Please close it and restart this program!'
                exit 1
        else
                #Inserts our imported bookmarks into Firefox's bookmark file
                tempbookmarks=`mktemp`
                profile=`cat "$docroot/$winuser/Application Data/Mozilla/Firefox/profiles.ini" | grep Path= | sed 's/Path=//' | sed 's/.$//'`

                #Takes evverything but the last line
                cat $bookmarks | sed '$d' > $tempbookmarks
                
                #Inserts new bookmarks
                cat "$docroot/$winuser/Application Data/Mozilla/Firefox/$profile/bookmarks.html" | sed '1,/<TITLE>/d' | sed '1 s/Bookmarks/Imported Firefox Bookmarks/' | sed '1 s/H1/H3/g' | sed 's/ID="*"//' | sed 's/PERSONAL_TOOLBAR_FOLDER="true"//' >> $tempbookmarks
                
                #Finish it off
                echo "</DL><p>" >> $tempbookmarks
                
                #Atomic baby
                mv $tempbookmarks $bookmarks
        fi      
}

#Find out what the user wants to import
ask_import() {
        zenity --list --checklist --column Import? --column Settings --text "Choose settings to import:" TRUE "IE Favorites" TRUE "Firefox Bookmarks" TRUE Wallpaper
}

#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
                fi
        done
}

#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..."
                fi
        done
}

find_winroot

ask_user

import=`ask_import`

if [[ -n `echo $import | grep "IE Favorites"` ]]
then
        import_bookmarks
fi

if [[ -n `echo $import | grep "Firefox Bookmarks"` ]]
then
        import_firefox_bookmarks
fi

if [[ -n `echo $import | grep Wallpaper` ]]
then
        mkdir -p "$HOME/Pictures/Wallpapers/"
        cp "$docroot/$winuser/Local Settings/Application Data/Microsoft/Wallpaper1.bmp" "$HOME/Pictures/Wallpapers/Imported.bmp"
        gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$HOME/Pictures/Wallpapers/Imported.bmp"
fi

MigrationAssistance/Script (last edited 2008-08-06 16:29:13 by localhost)