#!/bin/sh

[ $(basename $0) = "ice" ] && browser="iceweasel" || browser="firefox"

STORE="${HOME}/.mozilla/${browser}"
SRC="${STORE}/$(cat ${STORE}/profiles.ini | grep Path | head -n 1 | sed -e 's/Path=//')"
DST=/tmp/$(whoami)/${browser}-profile

[ -d ${SRC} ] || exit 1
echo haha
mkdir -p ${DST} || exit 1
echo hoho

if [ $# -eq 1 ]; then
	[ $1 = "--nosync" ] || rsync -av --delete-after ${SRC}/ ${DST}
	[ $1 = "--prepare" ] && exit 0
else
	$0 --prepare
fi


${browser} --profile ${DST}

[ -d "${DST}/datareporting" ] && rm -rf "${DST}/datareporting"
[ -d "${DST}/cache2" ] && rm -rf "${DST}/cache2"

[ $# -eq 1 -a "$1" = "--nosync" ] && exit 0

rsync -av --delete-after ${DST}/ ${SRC}
