#!/bin/bash # Packfox, a tool to facilitate running Firefox with its profile stored # in RAM. Copyright 2008-2009 Wicher Minnaard, wicher@gavagai.eu . # Distributed under the WFTPL, http://smormedia.gavagai.nl/dist/packfox/COPYING # Latest version available at http://smormedia.gavagai.nl/dist/packfox/ # Save this script as 'packfox' and hard/symlink it as 'packfox-daemon' # (or the other way around) in the same dir. # 'packfox' will invoke the packing. # 'packfox-daemon' will run a loop, watching for changes, calling 'packfox' if any. # both incantations will do checks, mounting, and unpacking. # Change this to match your correct profile PROFILE=$(hostname) PFDIR="${HOME}/.mozilla/firefox" # Tar every .. seconds (regardless of changes) TMOUT="1800" # But not more often than every .. seconds (regardless of changes) TMMIN="60" # Regex for which files not to act on when they're changed. # Use inotifywait -m -e modify -e move -e create -e delete --exclude '(/Cache/)' -r your_profile_dir # and do some browsing to determine which regex will be right for YOU. IEXCL="(.sqlite-journal$)|(\-log.txt$)|(cookies.sqlite$)|(sessionstore\-[0-9].js$)|(/weave/)|(/Cache/)" # Have you read everything and have you made the necessary adjustments? Then remove the line below ;-) #echo "I should read the comments and adjust the variables before running this script" && exit 2 # No user servicable parts below this line. TGT="${PFDIR}/${PROFILE}" # Global vars INOTYPID="" SLEEPPID="" PACKLOCK="" # Cleanup function terminate(){ # If we are the daemon and we get SIGINTed/SIGTERMed, kill our children # and if not already packing, do one last round of packing. if [ "$(basename ${0})" == "packfox-daemon" ] then if [ -n "${INOTIFYPID}" ]; then kill ${INOTIFYPID}; fi if [ -n "${SLEEPDPID}" ]; then kill ${SLEEPPID}; fi if [ -z "${PACKLOCK}" ];then packup; fi exit fi } # For cleaning up trap terminate SIGINT SIGTERM # Suicide with goodbye note. seppuku(){ echo "${1}" gxmessage "${1}" exit 2 } # Checks and setup test -d "${PFDIR}" || seppuku "Profile dir doesn't exist" if [ -z "$(mount -t tmpfs | grep -F "${TGT}" )" ] then mount "${PFDIR}/${PROFILE}" || seppuku "Mounting of profile's tmpfs failed; check fstab" fi test -f "${TGT}/.unpacked" || tar -xpf "${PFDIR}/${PROFILE}.packed.tar" -C "${PFDIR}" \ && touch "${TGT}/.unpacked" || seppuku "Error while untarring... You might want to use the backup tarball." # This tars up the profile packup(){ PACKLOCK="locked" cd "${PFDIR}" tar --exclude '.unpacked' -cpf "${PFDIR}/${PROFILE}.packed.tmp.tar" "${PROFILE}" mv "${PFDIR}/${PROFILE}.packed.tar" "${PFDIR}/${PROFILE}.packed.tar.old" mv "${PFDIR}/${PROFILE}.packed.tmp.tar" "${PFDIR}/${PROFILE}.packed.tar" PACKLOCK="" } # No daemon, just packing if [ "$(basename ${0})" == "packfox" ]; then packup; fi # The daemon loop if [ "$(basename ${0})" == "packfox-daemon" ] then which inotifywait >/dev/null 2>&1 || seppuku "Install sys-fs/inotify-tools first". while true do inotifywait -q -q -t ${TMOUT} -e modify -e move -e create -e delete --exclude "${IEXCL}" \ -r "${PFDIR}/${PROFILE}" & INOTYPID=${!} wait ${INOTYPID}; INOTIFYPID="" packup sleep ${TMMIN} & SLEEPPID=${!} wait ${SLEEPPID}; SLEEPPID="" done exit fi