Build Your Online Ebook Library
This article introduce a solution to build your own online E-book library which can be accessed from any dervice(based on web, so any device with a browser is okay) and anywhere(exposed on public internet with https and user authentication, convenient and safe). The core techniques used are Calibre and OneDrive.
Calibre is a outstanding open-source E-book management service, which provide great E-book reading, editing and converting experience. It is a desktop applications and store the library locally. OneDrive is a file sync service from Microsoft, compatible on windows, mac and linux service(via opensource tool OneDrive Client for Linux). Combine these two tools, we can read E-book on any desktop devices offline, and sync the library across devices once online.
But how about mobile? Don’t worry, Calibre has a feature called “content service” which can serve the library on web. We can deploy calibre content service on a server to provide the content of a Calibre library synced by OneDrive. Following content focuses on setting up the whole solution on a public, remote server.
Onedrive Client for Linux
Onedrive Client for Linux is a open-source onedrive cli, github link.
Installation
For ubuntu 24.04, don’t directly install onedrive from apt default repository(seems outdated), instead install from OpenSuSE Build Service repository. guide.
Usage
First, run onedrive , it will prompt an url used for authentication. Open the link in browser and login in to your Microsoft account. Once done, the browser will redrict you to a new url(which only appears shortly, so be quick), copy and paste the new link to onedrive to login in. The page may display text like “this is a incorrect page, you should never see the page.”, never mind.
Check config: use onedrive --display-config to print the current configuration. The sync dir is ~/OneDrive by default, which can be changed later.
Sync mode:
- Sync once:
onedrive --sync, oronedrive -s - Ongoing sync:
onedrive --monitororonedrive -m. Usually there’s no need to keep the process running in background on our own because onedrive has already installed a user level systemd configuration. Usesystemctl --user status/start/stop onedriveto manage the onedrive systemd daemon, which sync the files continuously.
⚠️Note: by default onedrive will sync all files from cloud. If you don’t want to sync everything, Client Side Filter can be used.
Client side filter: most client filters are exclude files(specify which kind of files not to sync), and only one sync-list config directly specify the files to sync. Create a file named sync-list in the onedrive config dir(by default ~/.config/onedrive) and add one file/dir per line. An example to only sync my Calibre library dir:
/Calibre-library/
Test the config: Onedrive Client for Linux provide a dry-run way to verify if the onedrive will sync the files exactly you want. Run onedrive --sync --dry-run to dry-run, which will print the operations to do instead of actually doing them.
Calibre content server
Installation
Calibre content service is a tool included in official Calibre release, and depends on the full version Calibre. Install calibre on ubuntu server using the official install script, refer to guide. If encounter any library missing error, install the missing library mentioned in the error message, or ask genAI tools for help. Finally calibre will be installed at /opt/calibre, with the calibre-server command which we will use to start a e-book content server.
Configuration
User management: I’d like to expose the content server on public internet, so both nginx reverse proxy and authenitcation is needed. Calibre content server itself support multi-user and user login, we can manage the user and password using calibre-server --manage-users, follow the promots to add new user or modify password for existing users.
Test the service: calibre-server /path/to/OneDrive/Calibre-library --port 38080 --enable-auth will start a calibre content server against the given library path and custome port, also need user to be authenticated to access the content. Try to run the command in shell to test if anything missing.
Create systemd service: Use systemd service to ensure the service always running in the background. refer to the following systemd file to setup systemd service:
1# /etc/systemd/system/calibre.service
2[Unit]
3Description=calibre Content server
4After=network.target
5
6[Service]
7Type=simple
8User=root
9ExecStart=/opt/calibre/calibre-server "/root/OneDrive/Calibre-library" --enable-auth --port 38080
10
11[Install]
12WantedBy=multi-user.target
Then you can use systemctl to manage the state of the calibre service. If you are not familiar with systemctl tool, just remember the following commonly used commands:
systemctl daemon-reload. reload the service config. Once you’ve modified the service file, run this to reload the service config.systemctl start calibrestart the calibre service. It will find the service with given service name and start the service in background.systemctl stop calibrestop the service.systemctl status calibrecheck the status of the service.
My new tips: If you run many services on a single server, it’s easy to forget which services are installed and running. My approach is to create an
appdir in the home directory, and create a directory for each service deployed on this server. For example, if the service is based on docker, I put the docker-compose.yaml file which define how to run the whole application in its dir. In this calibre case, I create a symbol link to the systemd file to remind me calibre is directly running on this machine and managed by systemd. When I want to see which services are running on the machine, I only need to check theappdirectory and will know how to manage each service.
Setup nginx reverse proxy: install nginx and create a new site configuration like this:
1 server {
2 listen 443 ssl http2;
3 server_name example.com;
4
5 ssl_certificate /etc/nginx/ssl/example.com.cert;
6 ssl_certificate_key /etc/nginx/ssl/example.com.key;
7
8 location / {
9 proxy_pass http://127.0.0.1:38080;
10 }
11 }
If you don’t have a certificate, don’t hurry to buy one. My suggestion is to use opensource certificate management & continuous deployment solution like certimate. It supports setting up a certificate workflow to check, apply and deploy the certificate to your server.
Access from browser
Use a password manager like Bitwarden to automatically get authenticated when accessing the Calibre website, then you don’t need to remember and input the username/password every time reading the e-books.