LINUX.ORG.RU

Работа с Firefox из tmpfs/Running a persistent Firefox profile from tmpfs

 , ,


1

0

Как известно, Firefox любит насиловать винт во время работы, особенно это касается файлов sessionstore.js, webappsstore.sqlite, places.sqlite и cookies.sqlite.

Я долго на это смотрел, скрипел зубами, не выдержал и написал скрипт, который выкидывает профиль в /tmpfs во время запуска, а потом синкает его обратно.

It's well known that Firefox likes thrashing your HDD when it works. This problem seriously affects these files: sessionstore.js, webappsstore.sqlite, places.sqlite and cookies.sqlite.

To solve this problem I've created a bash script which copies a Firefox profile to a temporary RAM based directory and then, when Firefox finishes, this script copies changed files back to a persistent directory.

Mode of action:

1) Edit: ~/.mozilla/firefox and add

[Profile1]
Name=firefox-tmpfs
IsRelative=1
Path=firefox-tmpfs

(if you already have more than one profile, Profile1 should become Profile2,3,4 etc.)

2) Create a directory ~/.mozilla/firefox/firefox-persistent
Within it:

mkdir ad
mkdir bk
mkdir ex
ln -s adblockplus $HOME/.mozilla/firefox/firefox-persistent/ad
ln -s extensions $HOME/.mozilla/firefox/firefox-persistent/ex
ln -s bookmarks $HOME/.mozilla/firefox/firefox-persistent/bk

3) Create a symbolic link from /tmp/firefox-tmpfs to ~/.mozilla/firefox/firefox-tmpfs

Create these two files:

$ cat > fxtmpfs.files
addons.sqlite
blocklist.xml
bookmarks.html
cert8.db
chromeappsstore.sqlite
compatibility.ini
content-prefs.sqlite
cookies.sqlite
downloads.sqlite
extensions.ini
extensions.sqlite
formhistory.sqlite
key3.db
lazarus-backup.sqlite
lazarus.sqlite
localstore.rdf
mimeTypes.rdf
permissions.sqlite
places.sqlite
pluginreg.dat
prefs.js
search.json
secmod.db
sessionstore.js
signons.sqlite
$ cat > fxtmpfs
#! /bin/bash

# v1.1

trap '' HUP

fxprofile=firefox-tmpfs
fxpersist=$HOME/.mozilla/firefox/firefox-persistent
dvolatile=/tmp/$fxprofile

die()
{
	xmessage -center "FATAL ERROR:
$@" &>/dev/null
	exit 1
}

copyback()
{
# $1 - old
# $2 - new
	fsize=`stat -c '%s' "$1"` || die "stat of $1 failed"

	md5old="X"
	if [ -f "$1" ]; then
		md5old=`md5sum "$1"` || die "md5sum of $1 failed"
	fi

	md5new="Y"
	if [ -f "$2" ]; then
		md5new=`md5sum "$2"` || die "md5sum of $2 failed"
	fi

	test -f "$2-journal" && die "WHAT THE FUCK IS GOING ON? YOU ARE STILL RUNNING FIREFOX!"

	if [ "$fsize" -gt 0 ]; then
		if [ "$md5new" != "$md5old" ]; then
			/bin/cp -a "$1" "$2" || die "cp from $1 to $2 failed!"
		fi
	fi
}

files="`dirname $0`/`basename $0`.files"
test -f $files || die "I cannot find $files"

if [ -d "$dvolatile" ]; then

	xmessage -center -timeout 5 "Temporary Firefox profile already exists." &>/dev/null &
else
	mkdir -p "$dvolatile" || die "mkdir of $dvolatile failed"
	# © Artem S. Tashkinov
	cp -a "$fxpersist"/* "$dvolatile" || die "cp of $fxpersist to $dvolatile failed"
fi

firefox -no-remote -P $fxprofile
xmessage -center -timeout 3 "Syncing Firefox profile in 3 seconds ..." &>/dev/null &
sync
sleep 3

for i in `cat "$files"`; do
	copyback "$dvolatile/$i" "$fxpersist/$i"
done

xmessage -center -timeout 5 "All done." &>/dev/null

chmod +x fxtmpfs

Run fxtmpfs.



Последнее исправление: juk4windows (всего исправлений: 1)

Молодец, навелосипедил. Мало того, что поиск по ЛОРу выдает N-ное количество подобных скриптов, так еще и вот.

kernelpanic ★★★★★
()

Как известно, Firefox любит насиловать винт во время работы

Использовать дисковый кеш для браузера? У вас калькулятор вместо компьютера или модемное соединение?

Deleted
()
2 июня 2013 г.

v1.2.2

#! /bin/bash

# Copyright (c) 2013 Artem S. Tashkinov. All rights reserved.
# v1.0 2012 Oct 24 03:51
# v1.1 Sun Oct 28 03:17:35 YEKT 2012 nohup and be verbose on shut down
# v1.2 Fri Nov 16 02:08:33 YEKT 2012 check if we are already running and finish
# v1.2.1 Sat Feb  9 02:20:20 YEKT 2013 announce start up
# v1.2.2 Sat Jun  1 05:55:33 YEKT 2013 voluntary back up, proper permissions for /tmp

export LANG=C # required for xmessage
trap '' HUP

fxprofile=firefox-vk
fxpersist=$HOME/.mozilla/firefox/firefox-vk-persistent
dvolatile=/tmp/$fxprofile

die()
{
	xmessage -center "FATAL ERROR:
$@" &>/dev/null
	exit 1
}

copyback()
{
# $1 - old
# $2 - new
	fsize=`stat -c '%s' "$1"` || die "stat of $1 failed"

	md5old="X"
	if [ -f "$1" ]; then
		md5old=`md5sum "$1"` || die "md5sum of $1 failed"
	fi

	md5new="Y"
	if [ -f "$2" ]; then
		md5new=`md5sum "$2"` || die "md5sum of $2 failed"
	fi

	test -f "$2-journal" && die "WHAT THE FUCK IS GOING ON? YOU ARE STILL RUNNING FIREFOX!"

	if [ "$fsize" -gt 0 ]; then
		if [ "$md5new" != "$md5old" ]; then
			/bin/cp -a "$1" "$2" || die "cp from $1 to $2 failed!"
		fi
	fi
}

files="`dirname $0`/`basename $0`.files"
test -f $files || die "I cannot find $files"

test -n "`ps ax | grep firefox | grep "$fxprofile" | grep -v grep`" && die "Firefox '$fxprofile' is already running - check another virtual desktop :)"

if [ -d "$dvolatile" ]; then
	xmessage -center -timeout 1 "Temporary Firefox profile already exists. Launching Firefox ..." &>/dev/null &
else
	xmessage -center -timeout 3 "Preparing Firefox profile ..." &>/dev/null &
	mkdir -p "$dvolatile" || die "mkdir of $dvolatile failed"
	chmod 700 "$dvolatile" || die "cannot set permissions"
	cp -a "$fxpersist"/* "$dvolatile" || die "cp of $fxpersist to $dvolatile failed"
	killall -9 xmessage &> /dev/null
	xmessage -center -timeout 1 "Launching Firefox ..." &>/dev/null &
fi

firefox -no-remote -P $fxprofile
xmessage -buttons "[ Save ],[ *Cancel* ]" -center -timeout 5 "Sync Firefox profile (5 seconds to answer)?" &>/dev/null
RES=$?

if [ "$RES" == "101" ]; then # Yes
	for i in `cat "$files"`; do
		sleep 1
		sync
		copyback "$dvolatile/$i" "$fxpersist/$i"
	done
	xmessage -center -timeout 5 "All done." &>/dev/null
else
	xmessage -center -timeout 5 "Bye, bye." &>/dev/null
fi
anonymous
()
Ответ на: комментарий от anonymous_sama

Мне плевать на «готовые» решения - я делаю для себя и чтобы работало как мне надо.

Ковыряться и разбираться в чужих скриптах нет никакого желания.

anonymous
()
Ответ на: комментарий от anonymous

Забежал и выбежал :-)

Всем спасибо за внимание.

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.