View Single Post
Old 02-03-2017, 02:55 PM   #48
kido.resuri
Groupie
kido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura aboutkido.resuri has a spectacular aura about
 
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
I read about triggers, and according to that, the database change should be easy to do with sql triggers.
Executing something like this [b]untested[/u] sql script on boot should do the update when virtual sd card is mounted and nickel updates it's library.

!WARNING! THE FOLLOWING IS ONLY THEORETICAL! IT WAS NOT TESTED ON A KOBO DEVICE! EDIT: It was tested. Buggy, but maybe safe.

This should be saved to a file "/root/library-virtual-sd.trigger"
Code:
-- usage:
--    $ sqlite3 /mnt/onboard/.kobo/KoboReader.sqlite < library-virtual-sd.trigger
DROP TRIGGER IF EXISTS update_library_virtual_content;
DROP TRIGGER IF EXISTS update_library_virtual_activity;

CREATE TRIGGER IF NOT EXISTS update_library_virtual_content AFTER INSERT ON content
BEGIN
 UPDATE content SET ContentID = REPLACE(ContentID,'/mnt/sd/virtual/','/mnt/onboard/virtualSD/'), BookID = REPLACE(BookID,'/mnt/sd/virtual/','/mnt/onboard/virtualSD/') WHERE rowid = new.rowid;
END;

CREATE TRIGGER IF NOT EXISTS update_library_virtual_activity AFTER INSERT ON Activity
BEGIN
 UPDATE Activity SET Id = REPLACE(Id,'/mnt/sd/virtual/','/mnt/onboard/virtualSD/') WHERE rowid = new.rowid;
END;
Then a script containing the following should be executed on boot once:
Code:
sqlite3 /mnt/onboard/.kobo/KoboReader.sqlite < /root/library-virtual-sd.trigger
The ebook files should be placed in /mnt/onboard/virtualSD/ and each newly added ebook should have a link copy in /mnt/onboard/.mysd/
Then mount the sd using the previously discussed method:

Code:
mount --bind /mnt/onboard/.mysd/ /mnt/sd/virtual
echo sd add /dev/mmcblk1p1 >> /tmp/nickel-hardware-status
I didn't test this yet, but in theory it should work.

In this case, /mnt/onboard/.mysd/ is a temp dir for links copies of the new content. It should be cleared on every boot and/or by the script that copy the content to the eReader, so only new content is added to the library. Using a dir in /mnt/onboard/ for the real files should be ok, as the content is already in the library, so nickel shouldn't add them on next USB connection. These are all untested yet.


EDIT: I tried the trigger offline, with SQLite Expert Personal, with this insert:
Code:
INSERT INTO content (ContentID,BookID,ContentType,MimeType,___UserID) VALUES ('file:///mnt/sd/virtual/testbook2.epub','/mnt/sd/virtual/testbook2.epub',6,'application/epub+zip','adobe_user');
The trigger works, and changes /mnt/sd/virtual/ to /mnt/onboard/virtualSD/ as expected. It seems that the trigger needs to be added only once, it will remain in the database until removed. Still need to be tested on Kobo.

Last edited by kido.resuri; 02-03-2017 at 04:53 PM. Reason: minor modifications
kido.resuri is offline   Reply With Quote