| 1 | #!/bin/bash |
| 2 | # Runs an isolated Firefox session in its own profile. - Matt 2007-12-02 |
| 3 | |
| 4 | #set -x |
| 5 | |
| 6 | MDD=~/.mozilla/firefox |
| 7 | |
| 8 | function write_profiles_ini { |
| 9 | ( |
| 10 | echo '[General]' |
| 11 | echo 'StartWithLastProfile=1' |
| 12 | echo |
| 13 | i=0 |
| 14 | for dir in *.*; do |
| 15 | if [ -d "$dir" ]; then |
| 16 | name="${dir#*.}" |
| 17 | echo "[Profile$i]" |
| 18 | echo "Name=$name" |
| 19 | echo "IsRelative=1" |
| 20 | echo "Path=$dir" |
| 21 | echo |
| 22 | let i=$i+1 |
| 23 | fi |
| 24 | done |
| 25 | ) >profiles.ini.tmp |
| 26 | mv profiles.ini.tmp profiles.ini |
| 27 | } |
| 28 | |
| 29 | function new_profile { |
| 30 | name="isolated-$$-$(date +%s)" |
| 31 | cp2 00000000.master/ "00000000.$name/" |
| 32 | write_profiles_ini |
| 33 | echo "$name" |
| 34 | } |
| 35 | |
| 36 | function liquidate_profile { |
| 37 | dir="00000000.$name" |
| 38 | cdir="changes_$name" |
| 39 | rsync -rl --compare-dest=../00000000.master --checksum "$dir/" "$cdir/" |
| 40 | rm -rf "$dir" |
| 41 | write_profiles_ini |
| 42 | find "$cdir" -type d -empty -delete |
| 43 | if [ -e "$cdir" ]; then |
| 44 | find_out="$(find "$cdir" -type f -print)" |
| 45 | zenity --info --text="This session changed the following files; you may wish to review the changes for application to the master profile: |
| 46 | |
| 47 | $find_out" |
| 48 | fi |
| 49 | } |
| 50 | |
| 51 | function run_isolated { |
| 52 | ff="$1" |
| 53 | shift |
| 54 | name="$(cd "$MDD"; new_profile)" |
| 55 | zenity --info --text="Beginning isolated Firefox session $name" |
| 56 | "$ff" -no-remote -P "$name" "$@" |
| 57 | (cd "$MDD"; liquidate_profile "$name") |
| 58 | } |
| 59 | |
| 60 | run_isolated /usr/bin/firefox "$@" |