#!/bin/bash # Runs an isolated Firefox session in its own profile. - Matt 2007-12-02 #set -x MDD=~/.mozilla/firefox function write_profiles_ini { ( echo '[General]' echo 'StartWithLastProfile=1' echo i=0 for dir in *.*; do if [ -d "$dir" ]; then name="${dir#*.}" echo "[Profile$i]" echo "Name=$name" echo "IsRelative=1" echo "Path=$dir" echo let i=$i+1 fi done ) >profiles.ini.tmp mv profiles.ini.tmp profiles.ini } function new_profile { name="isolated-$$-$(date +%s)" cp2 00000000.master/ "00000000.$name/" write_profiles_ini echo "$name" } function liquidate_profile { dir="00000000.$name" cdir="changes_$name" rsync -rl --compare-dest=../00000000.master --checksum "$dir/" "$cdir/" rm -rf "$dir" write_profiles_ini find "$cdir" -type d -empty -delete if [ -e "$cdir" ]; then find_out="$(find "$cdir" -type f -print)" zenity --info --text="This session changed the following files; you may wish to review the changes for application to the master profile: $find_out" fi } function run_isolated { ff="$1" shift name="$(cd "$MDD"; new_profile)" zenity --info --text="Beginning isolated Firefox session $name" "$ff" -no-remote -P "$name" "$@" (cd "$MDD"; liquidate_profile "$name") } run_isolated /usr/bin/firefox "$@"