View Single Post
Old 09-18-2011, 06:42 AM   #1
aruangra
Connoisseur
aruangra has learned how to read e-booksaruangra has learned how to read e-booksaruangra has learned how to read e-booksaruangra has learned how to read e-booksaruangra has learned how to read e-booksaruangra has learned how to read e-booksaruangra has learned how to read e-books
 
Posts: 78
Karma: 888
Join Date: May 2010
Device: Nook Touch, iPad1, iPad2, iPod Touch 4G, Pixel Qi
[HOW TO] Install Calibre in Intel-Based NAS

I think I should write up the instruction for installing Calibre on Intel-based NAS. Please refer to the following instruction. If you have any question, please let me know.

Best regards,
Anat Ruangrassamee

--------------------------------------------------------------------------------
How to install Calibre in Intel-Based NAS
18 September 2011

I successfully install Calibre on a Synology DS411+II NAS to run news fetching and the content server. I tried to compile libc but had several problems. The key to the success is “Debian 6 chroot environment”. This instruction may work for other Intel-based NASes for example QNAP.

NOTE: The instruction for the ARM-based NAS was added by smintman in the following posts.

Prerequisite
Bootstrapped NAS
For Synology, refer to
http://forum.synology.com/wiki/index...trap,_ipkg_etc
http://forum.synology.com/wiki/index...tall_Bootstrap

Steps
1. Preparing chroot environment on a PC
I followed the instruction in the following websites with slight modifications to create Debian 6.0.0 packages for i386 targets which is required by Calibre
http://kristof.vanhertum.be/?p=132
http://www.nslu2-linux.org/wiki/DS101/Debian

Code:
debootstrap --foreign --arch i386 squeeze chroottarget "http://ftp.de.debian.org/debian"
You may skip this step by simply downloading my chroot target file for the i386 architecture:
http://www.mediafire.com/?dbjgsc8v7u1dxps

2. Setup the chroot environment in your NAS
2.1 Copy the chroot target to a HDD in your NAS (/volume1/debian/ in this instruction) by any approach (FTP, NFS,etc). From now, you should use a terminal program to execute commands.
2.2 At the directory /volume1/debian/, uncompress the chroot target file using this command (Note: Don’t type # and anything in front of #)
Code:
ds # tar -xvf chroottarget.tar.gz
2.3 At the directory /volume1/debian/, finish debootstrap second stage on the target platform by using this command:
Code:
ds # chroot chroottarget /debootstrap/debootstrap --second-stage
2.4 Copy the file /etc/resolv.conf and /etc/hostname of your NAS to your chroot environment
Code:
ds # cp /etc/resolv.conf  /volume1/debian/chroottarget/etc/
ds # cp /etc/hostname /volume1/debian/chroottarget/etc/
3. Start up the chroot environment. Note that when you reboot your NAS, you need to run the following commands to start up the chroot environment.
At the directory /volume1/debian/, input this command:
Code:
ds # chroot chroottarget /bin/bash
The command prompt will be changed to chroot (for example “ds-chroot #”). Then input this command to mount “proc”
Code:
ds-chroot # mount -t proc proc /proc
4. Update apt-get and install some dependencies and programs.
Code:
ds-chroot# echo "deb ftp://ftp.debian.org/debian stable main contrib non-free" > /etc/apt/sources.list
ds-chroot# apt-get update
Then install dependencies for Calibre. This will install Calibre 0.7.7. Note that Calibre does not work in this step. This command is used only for getting necessary dependencies.
Code:
ds-chroot# apt-get install calibre 
ds-chroot# apt-get install python
ds-chroot# apt-get install bzip2
ds-chroot# apt-get install unzip
5. Install Calibre
5.1 Make the directory “calibre” in the directory “/opt”
5.2 Download Calibre from http://sourceforge.net/projects/calibre/files/ . You may use the newest version for i686 (I use Calibre 0.8.15 on my NAS.). You can download the file to your PC and then copy to /volume1/debian/chroottarget/opt/calibre. Then uncompress the file in the directory /opt/calibre
Code:
ds-chroot# bzip2 -dv calibre-0.8.15-i686.tar.bz2
Now, you have all program files in the directory /opt/calibre. Congratulations! Calibre should work now

6. Use Calibre
6.1 The recipes are in /opt/calibre/resources/ builtin_recipes.zip. Unzip the file and move the recipe you want to /opt/calibre
6.2 Make a directory “serve” in /opt/calibre for storing ebooks.
6.3 Run the content server by this command
Code:
/opt/calibre/calibre-server --with-library /opt/calibre/serve/ --port 8081 –-daemonize
6.4 Get news and update the database by this command
Code:
/opt/calibre/ebook-convert /opt/calibre/***.recipe /opt/calibre/***.epub
/opt/calibre/calibredb add --duplicates --with-library /opt/calibre/serve/ /opt/calibre/***.epub
7. Schedule news fetching
I use APScheduler 2.0.2 for python. Follow the instruction in this website:
http://pypi.python.org/pypi/APScheduler/
This is my script (script.py):

Code:
import os
import time
from apscheduler.scheduler import Scheduler

# Start the scheduler
sched = Scheduler()
sched.start()

def job_function1():
	os.system("/opt/calibre/ebook-convert /opt/calibre/cnn.recipe /opt/calibre/cnn.epub")
	os.system("/opt/calibre/calibredb add --duplicates --with-library /opt/calibre/serve/ /opt/calibre/cnn.epub")

	os.system('/opt/calibre/ebook-convert /opt/calibre/cnn.recipe /opt/calibre/cnn.mobi')
	os.system('/opt/calibre/calibre-smtp -r smtp.gmail.com -v --port 587 --username XXXXX@gmail.com --password YYYYY --a /opt/calibre/cnn.mobi --s "News Delivery" XXXXX@gmail.com ZZZZZ@free.kindle.com ""')

# Schedule
sched.add_cron_job(job_function1, day_of_week='mon-sun', hour=4, minute=0)

while True:
    time.sleep(10)
The last two lines will keep the script alive. To run the script in background, use this command:
Code:
nohup python script.py &
8. When rebooting the NAS, input the following commands to start up the scheduling script and the content server:
Code:
cd /volume1/debian/
chroot chroottarget /bin/bash
mount -t proc proc /proc
cd opt/calibre/
/opt/calibre/calibre-server --with-library /opt/calibre/serve/ --port 8081 --daemonize
nohup python script.py &

Last edited by aruangra; 09-22-2011 at 11:45 PM.
aruangra is offline   Reply With Quote