You are not logged in.

#1 2020-12-14 17:04:07

Xwang
Member
Registered: 2012-05-14
Posts: 353

[Solved] Synchronize PDF reading progress between two pc

Hi,
I have an USB pen with a lot of PDF and I would like to be able to read them both on my notebook and on an x86 tablet which I'm going to buy.
I'm going to install archlinux and kde on the tablet in the same way as I have on my notebook.
At the moment when I open a PDF, Okular is opened and when I open a file which I was already reading, the file is opened on the last page I was reading.
I would like to "synchronize" somehow the two pc so that if I stop reading a file on the pc and then I restart reading it on the tablet, it is automatically opened on the last page I was reading on the pc. And vice versa.
Using a virtualized archlinux with KDE system I have tried to do tha same and as expected, in the virtualized system the files are opened on the last pages they were when they were opened on that specific system.
So, to achieve my aim, is it possible to synchronize the two instances of Okular on two different PCs maybe configuring Okular to save and read its configuration files directly from the USB pen?
Is there any other way to do the same?
Is there any other portable software which I can install directly on the USB pen and use on my Linux PCs instead of Okular?
Finally, in case I have to use windows 10 on the tablet, is there any way to achieve the same between a linux and a windows system?
Thank you,
Xwang

Last edited by Xwang (2020-12-17 20:24:33)


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#2 2020-12-14 17:18:58

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: [Solved] Synchronize PDF reading progress between two pc

Check the /home/$USER/.local/share/okular/docdata/ folder.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#3 2020-12-14 18:01:08

Xwang
Member
Registered: 2012-05-14
Posts: 353

Re: [Solved] Synchronize PDF reading progress between two pc

Lone_Wolf wrote:

Check the /home/$USER/.local/share/okular/docdata/ folder.

Thank you very much.
At least now I know how Okular is able to reopen to the last page.
It seems theoretically possible to create a script that copies that directory to the USB pendrive before unmounting it and another script that copies from the pendrive to the folder every time the pendrive is mounted.
But since the url in the xml files are absolute one it is needed to have the same username and configure the PCs so that to mount the pendrive in the same url.
It seems a be a bit complicated and error prone. Isn't it?


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#4 2020-12-14 21:53:26

Xwang
Member
Registered: 2012-05-14
Posts: 353

Re: [Solved] Synchronize PDF reading progress between two pc

Maybe I've found a solution.
I've created the following script file in the root of the usb pen and I've named it OkularLinuxPortable.sh:

#!/bin/bash
firejail --caps.drop=all --blacklist=/dataBackup --disable-mnt --private=./ okular $1

I have made it executable and executing it with ./OkularLinuxPortable.sh ./relativePathtoFile/fileName.pdf, forces okular to see the root of the usb pen as the home and so the .local/share/okular/docdata/ folder is created in the USB pen.
Unmounting the USB and mounting in the virtualbox archlinux (which of course has to have okular and firejail installed and configured), it has opened the file where I left in the not virtualized archlinux.
So it has somewhat worked, but it works only for files which are in the USB pen (which is not an issue because it is what I need).


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#5 2020-12-16 17:00:40

Xwang
Member
Registered: 2012-05-14
Posts: 353

Re: [Solved] Synchronize PDF reading progress between two pc

I have changed my mind and I think that it is better to synchronize the /home/$USER/.local/share/okular/docdata/ and avoid the solution based on firejail even thought it works as a proof of concept.
So in order to syncronize that folder my idea is to configure the two PCs to do the following:
1) everytime the USB pen is unmounted the folder is copied (with grsync or rsync) to a specific folder on the USB pen
2) everytime the USB pen is mounted, the content of the folder on the USB is copied (with grsync or rsync) to the  /home/$USER/.local/share/okular/docdata/ overwiting older existing files and keeping files which are there but not in the USB pen

The second point can be made creating a systemd service similar to the one I've already done to backup a folder of the usb pen to the PC and which is the following:

[Unit]
Description=Exec backintime backup of KIN128GB pendrive on mount
Requires=run-media-andreak-KIN128GB.mount
After=run-media-andreak-KIN128GB.mount

[Service]
ExecStart=/home/andreak/bin/backintimeKIN128GB.sh

[Install]
WantedBy=run-media-andreak-KIN128GB.mount

A problem that I have at the moment is that I cannot use the same approach to do the first point above because there is no run-media-andreak-KIN128GB.umount which I can use with the Before action to understand when the USB pen is going to be unmounted.
Am I missing something?
Any idea?


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#6 2020-12-16 18:40:53

Xwang
Member
Registered: 2012-05-14
Posts: 353

Re: [Solved] Synchronize PDF reading progress between two pc

Maybe I could use this approach:
https://bartsimons.me/sync-folders-and- … d-inotify/
but I have to find a way to automatically enable the service when the USB is connected and disable it when it is removed.


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#7 2020-12-17 13:06:59

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: [Solved] Synchronize PDF reading progress between two pc

You may to able to use udev rules for that.
https://wiki.archlinux.org/index.php/Ud … le_example

Disclaimer : I have never written an udev rule, could be wrong


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#8 2020-12-17 20:24:10

Xwang
Member
Registered: 2012-05-14
Posts: 353

Re: [Solved] Synchronize PDF reading progress between two pc

I've solved with this script
$HOME/bin/okularSyncKIN128GB.sh

#!/bin/bash

LOCALDIR=$HOME/.local/share/okular/docdata
USBDIR=/run/media/$USER/KIN128GB/okular
if [ -d "$USBDIR" ]
then
    ##Syncing data from USBDIR to LOCALDIR only one time at the beginning of the execution when the USB has hust been connected
    rsync -auvr $USBDIR/ $LOCALDIR

    ##While the USBDIR exists if any modification is made to LOCALDIR, a syncronization is made from LOCADIR to USBDIR
    while [ -d "$USBDIR" ]; do
        inotifywait -r -e modify,attrib,close_write,move,create,delete $LOCALDIR
        rsync -auvr  $LOCALDIR/ $USBDIR
    done
fi
echo "$LOCALDIR does not exist anymore. Goodbye!"
exit 0

used by this systemd user service (enabled with systemcl --user $HOME/.config/systemd/user/okularSyncKIN128GB.service)

$HOME/.config/systemd/user/okularSyncKIN128GB.service

[Unit]
Description=Sync okular docdata from KIN128GB pendrive on mount and to KIN128GB pendrive until it is mounted
BindsTo=run-media-%u-KIN128GB.mount
After=run-media-%u-KIN128GB.mount

[Service]
ExecStart=%h/bin/okularSyncKIN128GB.sh

[Install]
WantedBy=run-media-%u-KIN128GB.mount

They are installed on both PCs and in order to run rsync and inotify-tools need to be installed on both PCs too.
When the USB is mounted the service is automatically started and when the USB is unmounted since the service is BindTo the mount service, it is automatically stopped and so the inotify process.
Of course KIN128GB is the label of the pendrive.
I put here in case someone else need to do something similar.
Thank Lone_Wolf for your help.


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#9 2021-04-14 23:32:53

Xwang
Member
Registered: 2012-05-14
Posts: 353

Re: [Solved] Synchronize PDF reading progress between two pc

I have a weird problem.
I have just started using this method between my laptop (arch) and my tablet (android with debian testing installed in chroot using linux deploy).
The issue is that when I move the exfat sdcard from the tablet to the laptop, the laptop see the modification date one hour in the future and so rsync fails to correctly update files.
Is there any way to solve this?


I'm still learning English so please excuse me if my English is not good enough and feel free to correct me via PM if you want.

Offline

#10 2021-04-15 11:06:14

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,911

Re: [Solved] Synchronize PDF reading progress between two pc

Sounds like it could be related to Daylight Saving Time .

exFAT (and FAT) uses local time for timestamps , not UTC .

https://freefilesync.org/manual.php?top … aving-time seems to give a decent explanation .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB