Setup Calibre on FreeBSD


This article describes the installation of a calibre-based ebook server via ansible on a RaspberryPi running FreeBSD

Installing the system

Note: All snippets are meant to be part of an ansible configuration file.

  - name: install calibre
      name: calibre
      state: present

We we'll use a distinct calibre user and corresponding group for running the server. Also, an init script which is provided by the installation of the calibre package is using the calibre user per default.

  - name: ensure group "calibre" exists
      name: calibre
      state: present

Create the corresponding user calibre with main group calibre.

  - name: create user "calibre" with primary group "calibre"
      name: calibre
      group: calibre

In the current system setup, there will be a folder /Calibre_Library that contains the books and metadata.db. As an alternative, you can think about an external drive (e.g. usb stick, ssd, nfs) for storing the library.

  - name: create library directory
      path: /Calibre_Library
      state: directory

If we stay with an empty directory, calibre_server will raise an error that Calibre_Library is not a library. Most probably that has someting to do with a missing metadata.db file. For that reason we will "init" the library with a "dummy" book.

  - name: adding quick start guide
    shell: calibredb add /usr/local/share/calibre/quick_start/deu.epub --library-path /Calibre_Library

The former command was executed as root user that leads to a problem with the access rights. We fix that by chown the complete library folder with all it's files to the calibre user.

  - name: set ownership of library path to user calibre
      path: /Calibre_Library
      state: directory
      owner: calibre
      group: calibre
      recurse: yes

For OPDS and adding books from a remote host via command line, we need to authenticate us as a valid user. Create a user database that is used by calibre-server for authentication.

  - name: create userdb
      command: calibre-server --userdb /usr/local/etc/cbusers.sqlite --manage-users
      creates: /usr/local/etc/cbusers.sqlite
	(.*)What do you want to do?(.*): "1"
	(.*)Enter the username(.*): "test"
	(.*)Enter the new password for(.*): "test"
	(.*)Re-enter the new password for(.*): "test"

Finally, we will add a calibre server entry to /etc/rc.conf because otherwise the service is not allowed to be started. Here, we're using freebsd's calibre service file that comes with the installation of calibre package. Some remarks:

  - name: enable calibre server in rc
      path: /etc/rc.conf
      marker: "# {mark} ANSIBLE MANAGED CALIBRE BLOCK"
      block: |
	calibre_flags="--userdb /usr/local/etc/cbusers.sqlite --enable-auth --listen-on --worker-count=1"