Move Firefox Bookmarks between AppVMs - Help with Script

80 views
Skip to first unread message

[799]

unread,
May 5, 2018, 4:44:50 PM5/5/18
to qubes...@googlegroups.com
Hello,

following a recent discussion in the qubes-community github repository, Ivan has written an interesting script for handling links and disposable VMs.
This has inspired me to look how to move firefox bookmarks to other AppVMs.
While disposable VMs are great, sometimes it is handy to have bookmarks available in an AppVM.

I was able to import bookmarks into other Appvms by transfering the places.sqlite file which holds the bookmarks.

In the target AppVM which has the bookmarks:
qvm-copy-to-vm <AppVMdestination> /home/user/.mozilla/firefox/*.default/places.sqlite

then in the destination VM you only need to move the file from QubesIncoming to the profile path.
While this works, I like to add some error checking and I would also like to kill a running firefox in the destination AppVM.

I was able to kill firefox running:

kill `ps -A | grep firefox | gawk '{ print $1 }'`

no I tried to run further command based on the fact if firefox is running or not.
I thereof tried to do something like this:

if [`ps -A | grep firefox | gawk '{ print $1 }'` \> 0]; then
echo "Run this when PID is > 0 and thereof Firefox is running"
else
echo "Run this when firefox is not running"
fi

Unfortunately this doesn't work. Can somone point me into the right direction?
What is the right approach to run certain commands based on the fact that a program is running or not?

Sorry for this off-topic question but playing with Qubes gives so much options for building own scripts and I am still a beginner here.

[799]

Manuel Amador (Rudd-O)

unread,
May 5, 2018, 9:44:11 PM5/5/18
to [799], qubes...@googlegroups.com
You are probably better off writing something that will sync two
different .sqlite files by using SQL operations on both.  SQLite files
are safe to be accessed by two different programs at the same time, and
therefore you may not need to kill Firefox.

--
Rudd-O
http://rudd-o.com/

799

unread,
May 6, 2018, 3:03:31 AM5/6/18
to Manuel Amador (Rudd-O), qubes...@googlegroups.com
Hello rudd-o,


Manuel Amador (Rudd-O) <rud...@rudd-o.com> schrieb am So., 6. Mai 2018, 03:44:
On 2018-05-05 20:44, [799] wrote:
> (....) I thereof tried to do something
> like this:
>
> if [`ps -A | grep firefox | gawk '{ print $1 }'` \> 0]; then
>    echo "Run this when PID is > 0 and thereof Firefox is running"
> else
>    echo "Run this when firefox is not running"
> fi
>
> Unfortunately this doesn't work. Can somone point me into the right direction?

This is still not solved, I like to know how to make this work, also because I might need this for other purposes.

You are probably better off writing something that will sync two
different .sqlite files by using SQL operations on both.  SQLite files
are safe to be accessed by two different programs at the same time, and
therefore you may not need to kill Firefox.

You are right, but this is something that is currently beyond my skillet as I need to learn python and sqlite.
There is an interesting tutorial which might be helpful, but it will take some time for me ...

As an additional task I need to understand how the sqlite database is setup/working in order to merge bookmarks from two different places.sqlite files.
I think the easiest way would look like:

1) dump data from sqlite (even while Firefox is running
2) copy dumpfile to destination VM
3) import dump and overwrite the existing entries in the places.sqlite

If I has the dump export/import part I can take care of the rest.
The idea is that I can start a disposable VM and then "push" the firefox bookmarks of another VM into this disposable VM.

[799]

trueriver

unread,
May 6, 2018, 6:21:28 AM5/6/18
to qubes-users
On Saturday, 5 May 2018 21:44:50 UTC+1, [ 799 ] wrote:
> Hello,
>
> following a recent discussion in the qubes-community github repository, Ivan has written an interesting script for handling links and disposable VMs.
> This has inspired me to look how to move firefox bookmarks to other AppVMs.

Be careful propagating bookmarks - some will contain info that is usable for tracking purposes (long strings of hex or alphanumeric gobbeldygook are a strong hint). If the url contains parts that do not look straightforward, please think about the reasons you were using a disp VM in the first place. It might or might not matter to you, but do make that an informed choice.


Another two ways to do this, which have security implications so will not be for everyone, each involve a throwaway email address.

Method 1: to use that address to register with mozilla. Then mozilla will sync your bookmarks when you log in

You can even have a variety of mozilla accounts to keep one set of bookmarks separate from another.

The security issue is that for some use cases, having an outside entity like mozilla tracking you might be worse than using a non-disposable VM. Remember that by default mozilla will also track history, and for some people that is exactly what they are trying to avoid.

But where manageable, this is the easiest to set up - and you are in control of each connection because with a disp VM, mozilla only makes the connection after you voluntarily log in.

A second way is to create a throwaway gmail account, and create draft emails that contain the links you would otherwise bookmark. You go into gmail to look at those drafts. Becasue the email is never sent, it is never sniffed.

The security risk here involves the US authorities requisitioning from google the details of accounts with long term drafts (especially of interest if those addresses never email out because the draft email strategy is well understood by the securit agencies). Google would not be allowed to tell us whether this is already routinely happening.... :(

So there are good reasons why many of you will not want to use either strategy. Or not all the time anyway

Stuart Perkins

unread,
May 6, 2018, 11:43:05 AM5/6/18
to qubes...@googlegroups.com
I would accomplish bookmarks within disposable vm by...

Create an exported tar file of a profile, including the control file for firefox which defines the default profile.
Start the disposable vm for terminal.
qvm-copy-to-vm the tar file
extract tar
run script
start firefox

It would be a little bit "manual" but would accomplish the goal. The tar file would be recreated when bookmarked site login info changed etc...

Just my take on it.

MirrorWay

unread,
May 6, 2018, 11:50:38 AM5/6/18
to qubes...@googlegroups.com
On May 5, 2018 8:44 PM, [799] <one7...@gmail.com> wrote:

> Hello,
>
> following a recent discussion in the qubes-community github repository, Ivan has written an interesting script for handling links and disposable VMs.
>
> This has inspired me to look how to move firefox bookmarks to other AppVMs.
>
> While disposable VMs are great, sometimes it is handy to have bookmarks available in an AppVM.
>
> I was able to import bookmarks into other Appvms by transfering the places.sqlite file which holds the bookmarks.
>
> In the target AppVM which has the bookmarks:
>
> qvm-copy-to-vm <AppVMdestination> /home/user/.mozilla/firefox/*.default/places.sqlite
>
> then in the destination VM you only need to move the file from QubesIncoming to the profile path.
>
> While this works, I like to add some error checking and I would also like to kill a running firefox in the destination AppVM.

Isn't this a one-time import? I'm not sure why you need to automate this process, Seems like the VM that stores bookmarks could get compromised eventually if it parses SQL files constantly.

> I thereof tried to do something like this:
>
> if [`ps -A | grep firefox | gawk '{ print $1 }'` > 0]; then
>
> echo "Run this when PID is > 0 and thereof Firefox is running"
>
> else
>
> echo "Run this when firefox is not running"
>
> fi

I'm not sure why firefox PID would ever be 0?
If firefox isn't running, it won't show in ps. So:
if ps -A | grep -q firefox; then .... else ... fi

assuming any process whose name contains "firefox" is actually firefox.


Ivan Mitev

unread,
May 7, 2018, 1:28:21 AM5/7/18
to qubes...@googlegroups.com
Hi,

On 05/05/2018 11:44 PM, [799] wrote:
> Hello,
>
> following a recent discussion in the qubes-community github repository, Ivan has written an interesting script for handling links and disposable VMs.
> This has inspired me to look how to move firefox bookmarks to other AppVMs.
> While disposable VMs are great, sometimes it is handy to have bookmarks available in an AppVM.
>
> I was able to import bookmarks into other Appvms by transfering the places.sqlite file which holds the bookmarks.

Interestingly I investigated this a few weeks ago; an alternative to
copying the sqlite file (or using sql commands as suggested by rudd-o)
is to automatically import/export bookmarks as an html file. See:

https://support.mozilla.org/en-US/questions/928809#answer-338913

you shouldn't need to delete the sqlite file in the target VM if you set
this:

http://kb.mozillazine.org/Browser.places.importBookmarksHTML

The bookmark format looks straightforward so it should be possible to
merge two html files with basic commands (sed/grep/awk/...) before
importing. But you might be better off using buku
(https://github.com/jarun/Buku) to import bookmarks, and then export
them ; it's quite powerful...



> In the target AppVM which has the bookmarks:
> qvm-copy-to-vm <AppVMdestination> /home/user/.mozilla/firefox/*.default/places.sqlite
>
> then in the destination VM you only need to move the file from QubesIncoming to the profile path.
> While this works, I like to add some error checking and I would also like to kill a running firefox in the destination AppVM.
>
> I was able to kill firefox running:
>
> kill `ps -A | grep firefox | gawk '{ print $1 }'`

you could also use `pkill firefox`

>
> no I tried to run further command based on the fact if firefox is running or not.
> I thereof tried to do something like this:
>
> if [`ps -A | grep firefox | gawk '{ print $1 }'` \> 0]; then
> echo "Run this when PID is > 0 and thereof Firefox is running"
> else
> echo "Run this when firefox is not running"
> fi

The problem when using 'grep' is that 'ps' may output the 'grep' line
itself so even if the process doesn't exist you'll get a match; eg.

$ ps aux | grep nosuchprocess

user 6837 [..] grep --color=auto nosuchprocess

(although 'ps -A' doesn't seem to have this behavior)

to avoid that, a trick is to use a regex like that:

if ps -A | grep -q [f]irefox; then ...

alternatives:

if pgrep firefox > /dev/null; then ...
if [ -n "$(pgrep firefox)" ]; then ...
if [ -n "$(pidof firefox)" ]; then ...

and as a side note you can use a short 'if' construct like that if you
have only short commands:

[ -n "$(pgrep firefox)" ] && echo running || echo not running

799

unread,
May 7, 2018, 2:26:51 AM5/7/18
to Ivan Mitev, qubes...@googlegroups.com
Hello Ivan,

sorry for top-posting, but as everything you mentioned is super interesting and very helpful ... Thank you!

The auto export bookmarks feature is nice, didn't know that and if places.sqlite also includes the browser history I will not use the "copy places.sqlite file"-approach, because one reason why I am using a disposable AppVM is exactly because I don't want to have my history seen.

So the only task is to qvm-copy the latest auto-bookmarks export file into the right location on the dispvm.
There is one problem (maybe):
I need to check if a firefox profile folder exists in the disposable VM.
Not sure if this is the case as each disposable VM is a "fresh" one.

Thanks again for your scripting tips - this is why I love the Qubes Community :-)

[799]

Drew White

unread,
May 7, 2018, 3:00:48 AM5/7/18
to qubes-users
[799],

If it's only for FF you want it, why not have an FF sync server on your local?
I have built myself a local DNS guest with a lot of bells and whistles.

It allows me to perform sharing and more between guests. All only accessible from inside my PC.

ALL DNS requests are stored and filtered properly.
ALL blocked things get a local page that provides blocked details.

I can pretty much do what I want to.
So setting a similar thing up as an FF account Sync server should not be too difficult, if that is what you are interested in?

Reply all
Reply to author
Forward
0 new messages