update on firefox profile wrapper script

May 27, 2010

This version looks at lock files instead of parsing the process list.

#!/bin/sh
FIREFOX_PROFILE_DIR=~/.mozilla/firefox
FIREFOX_DEFAULT_PROFILE=default

search_ini () {
  IFS="=" 
  file=$1
  search_key=$2
  search_value=$3
  want=$4
  inside=
  while read f1 f2; do 
    case "$f1" in
      $search_key)
        if [ "$f2" = "$search_value" ]; then
          inside=1;
        fi
        ;;
      $want)
        if [ -n "$inside" ]; then
          result="$f2"
          return
        fi
        ;;
    esac
  done < $file
}

search_ini $FIREFOX_PROFILE_DIR/profiles.ini "Name" "$FIREFOX_DEFAULT_PROFILE" "Path"
if [ -z "$result" ]; then
  echo "failed to find firefox profile dir for $FIREFOX_DEFAULT_PROFILE"
  exit 1
fi

#if ps ax | grep -q "[/]firefox.* -P default --no-remote"; then
if [ -h $FIREFOX_PROFILE_DIR/$result/lock ]; then
  # use the old fox
  /usr/bin/firefox -P default $@
else
  # start a fresh fox
  /usr/bin/firefox -P default --no-remote $@
fi

Follow

Get every new post delivered to your Inbox.