diff --git a/roles/6-generic-apps/tasks/main.yml b/roles/6-generic-apps/tasks/main.yml index f30a94d46..0f8bd75a9 100644 --- a/roles/6-generic-apps/tasks/main.yml +++ b/roles/6-generic-apps/tasks/main.yml @@ -3,12 +3,6 @@ - name: ...IS BEGINNING ==================================== command: echo -- name: CALIBRE - include_role: - name: calibre - when: calibre_install - tags: calibre - - name: DOKUWIKI include_role: name: dokuwiki diff --git a/roles/8-mgmt-tools/tasks/main.yml b/roles/8-mgmt-tools/tasks/main.yml index ad22382ed..dc0cb270e 100644 --- a/roles/8-mgmt-tools/tasks/main.yml +++ b/roles/8-mgmt-tools/tasks/main.yml @@ -51,6 +51,12 @@ when: xovis_install and ansible_distribution != "CentOS" tags: xovis +- name: CALIBRE + include_role: + name: calibre + when: calibre_install + tags: calibre + - name: Recording STAGE 8 HAS COMPLETED ====================== lineinfile: dest=/etc/iiab/iiab.env regexp='^STAGE=*' diff --git a/roles/calibre/defaults/main.yml b/roles/calibre/defaults/main.yml index 9cfb2630f..84b572e62 100644 --- a/roles/calibre/defaults/main.yml +++ b/roles/calibre/defaults/main.yml @@ -1,6 +1,16 @@ calibre_port: 8080 -calibre_web_path: calibre -# In addition to: http://box/books box/libros box/livres box/livros box/liv -calibre_dbpath: "/library/calibre" +# http://box:8080 & http://box:8080/mobile WORK BUT THESE OTHER URL'S ARE A MESS (BOOKS RARELY DISPLAY) +calibre_web_path: calibre +# In addition to: http://box:8080 http://box/books box/libros box/livres box/livros box/liv + +calibre_dbpath: "{{ content_base }}/calibre" +# i.e. /library/calibre + +calibre_sample_book: "Metamorphosis-jackson.epub" +# Must be downloadable from http://download.iiab.io/packages + calibre_src_url: "https://raw.githubusercontent.com/kovidgoyal/calibre/master/setup/linux-installer.py" + +calibre_debs_on_debian: false +# USE TO TEST debs.yml (RASPBIAN APPROACH!) ON DEBIAN 9.X diff --git a/roles/calibre/tasks/create-db.yml b/roles/calibre/tasks/create-db.yml new file mode 100644 index 000000000..be3c47f8f --- /dev/null +++ b/roles/calibre/tasks/create-db.yml @@ -0,0 +1,35 @@ +- name: Create /library/calibre (mandatory since Calibre 3.x) + file: + path: "{{ calibre_dbpath }}" + state: directory + #mode: 0755 + +- name: Check if sample book exists in /opt/iiab/downloads + stat: + path: "{{ content_base }}/downloads/{{ calibre_sample_book }}" + register: sample_bk + +- name: Download sample book (mandatory since Calibre 3.x) + get_url: + url: "{{ iiab_download_url }}/{{ calibre_sample_book }}" + dest: "{{ content_base }}/downloads" + when: internet_available and not sample_bk.stat.exists + +- name: Check if sample book exists in /opt/iiab/downloads + stat: + path: "{{ content_base }}/downloads/{{ calibre_sample_book }}" + register: sample_bk + +- name: Incorporate sample book into Calibre DB (mandatory since Calibre 3.x) + shell: "calibredb add {{ content_base }}/downloads/{{ calibre_sample_book }} --with-library {{ calibre_dbpath }}" + when: sample_bk.stat.exists + +- name: Make /library/calibre/metadata.db writable for Calibre client SW + file: + path: "{{ calibre_dbpath }}/metadata.db" + mode: "ugo+w" + #mode: 0666 + #owner: pi + #group: pi + #owner: iiab-admin + #group: iiab-admin diff --git a/roles/calibre/tasks/debs.yml b/roles/calibre/tasks/debs.yml new file mode 100644 index 000000000..64c6504a2 --- /dev/null +++ b/roles/calibre/tasks/debs.yml @@ -0,0 +1,7 @@ +- name: Start by installing OS's Calibre package + package: + name: calibre + state: present + +- name: Upgrade latest Calibre + command: scripts/calibre-install-latest.sh diff --git a/roles/calibre/tasks/main.yml b/roles/calibre/tasks/main.yml index 2383f9601..5b999d9f1 100644 --- a/roles/calibre/tasks/main.yml +++ b/roles/calibre/tasks/main.yml @@ -1,62 +1,88 @@ -- name: Get Calibre setup file (CentOS) -# the installer works for intel fedora, and Centos, and deals with dependencies - get_url: - url="{{ calibre_src_url }}" - dest="{{ downloads_dir }}/calibre-installer.py" - mode=0755 - when: ansible_distribution == "CentOS" +# 1. INSTALL THE LATEST CALIBRE 3.X+ (calibre-server etc) ON ALL OS'S -- name: Install Calibre (CentOS) - shell: "{{ downloads_dir }}/calibre-installer.py >> /dev/null" - args: - creates: /usr/bin/calibre-uninstall - when: calibre_install and ansible_distribution == 'CentOS' +# RUNS IF /usr/bin/calibre-uninstall DOES NOT ALEADY EXIST +- name: Install Calibre via calibre-installer.py (OS's other than Raspbian) + include_tasks: py-installer.yml + when: (not is_rpi) and (not calibre_debs_on_debian) + #when: is_redhat or is_ubuntu -- name: Install Calibre (OS's other than CentOS) -# the fedora rpm arm version, though older, takes care of dependencies, and exists - package: name={{ item }} - state=present - with_items: - - calibre - when: calibre_install and ansible_distribution != 'CentOS' +- name: Install Calibre via .debs (Raspbian) + include_tasks: debs.yml + when: is_rpi or calibre_debs_on_debian + #when: is_rpi or is_debian # (is_debian also covers & includes is_rpi) + +# 2. STOP CALIBRE SERVICE IF IT EXISTS (REQUIRED FOR DB ACTIVITY...AND IF not calibre_enabled) + +#- name: Check if Calibre systemd service exists +# stat: +# path: /etc/systemd/system/calibre-serve.service +# register: calibre_svc + +- name: Stop Calibre service -- calibre-server by Kovid Goyal +# systemd: + service: + name: calibre-serve + state: stopped + #enabled: no +# register: command_result # gist.github.com/tyrells/0a79681de339237cb04c + failed_when: false # Never Fail during "systemctl stop calibre-serve" (even if service doesn't exist!) +# when: calibre_svc.stat.exists + +# 3. CREATE DATABASE WITH A SAMPLE BOOK (REQUIRED AS OF CALIBRE 3.x) + +- name: Check if /library/calibre/metadata.db exists + stat: + path: "{{ calibre_dbpath }}/metadata.db" + register: calibre_db + +- name: Create database (required since Calibre 3.x) with a sample book + include_tasks: create-db.yml + when: not calibre_db.stat.exists + +# 4. WRAP UP: CALIBRE SERVICE, http://box/books ETC - name: Create calibre-serve.service and calibre.conf - template: backup=no - src={{ item.src }} - dest={{ item.dest }} - owner=root - group=root - mode={{ item.mode }} + template: + backup: no + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: root + group: root + mode: "{{ item.mode }}" with_items: - { src: 'calibre-serve.service.j2', dest: '/etc/systemd/system/calibre-serve.service', mode: '0644'} - { src: 'calibre.conf', dest: '/etc/{{ apache_config_dir }}', mode: '0644'} - when: calibre_install - -- name: Create the link for sites-enabled, containing ProxyPass[Reverse]...localhost:8080 (debuntu) - file: src=/etc/apache2/sites-available/calibre.conf - dest=/etc/apache2/sites-enabled/calibre.conf - state=link - when: is_debuntu and calibre_enabled - -- name: Enable Calibre service -- runs calibre-server by Kovid Goyal - service: name=calibre-serve - enabled=yes - state=started - #async: 900 - #poll: 5 when: calibre_enabled -- name: Disable Calibre service -- stops calibre-server by Kovid Goyal - service: name=calibre-serve - enabled=no - state=stopped - when: not calibre_enabled +# http://box:8080 & http://box:8080/mobile WORK BUT OTHER URL'S LIKE http://box/books ARE A MESS (BOOKS RARELY DISPLAY) +- name: Create calibre.conf link for UNTESTED http://box/books etc (debuntu) + file: + src: /etc/apache2/sites-available/calibre.conf + dest: /etc/apache2/sites-enabled/calibre.conf + state: link + when: calibre_enabled and is_debuntu -- name: Add 'calibre-serve' to service list - ini_file: dest='{{ service_filelist }}' - section=calibre - option='{{ item.option }}' - value='{{ item.value }}' +- name: Remove calibre.conf link if disabled (debuntu) + file: + dest: /etc/apache2/sites-enabled/calibre.conf + state: absent + when: (not calibre_enabled) and is_debuntu + +- name: Enable Calibre service -- runs calibre-server by Kovid Goyal + service: + name: calibre-serve + enabled: yes + state: started + when: calibre_enabled + #async: 900 + #poll: 5 + +- name: Add 'calibre-serve' to service list at /etc/iiab/iiab.ini + ini_file: + dest: "{{ service_filelist }}" + section: calibre + option: "{{ item.option }}" + value: "{{ item.value }}" with_items: - option: description value: '"Calibre is an extremely popular personal library system for e-books."' diff --git a/roles/calibre/tasks/py-installer.yml b/roles/calibre/tasks/py-installer.yml new file mode 100644 index 000000000..4480405ea --- /dev/null +++ b/roles/calibre/tasks/py-installer.yml @@ -0,0 +1,51 @@ +# Seems to work with just about any Linux (Fedora 18 on OLPC XO Laptops??) and deals with dependencies. +# But is arch dependent: requires x86_64 or i686 for now. + +- name: Download latest linux-installer.py from GitHub to calibre-installer.py + get_url: + url: "{{ calibre_src_url }}" + dest: "{{ downloads_dir }}/calibre-installer.py" + mode: 0755 + force: yes + backup: yes + register: calibre_download_output + when: internet_available + +# ALWAYS DEFINED, DESPITE get_url DOCUMENTATION CLAIM... +# - debug: +# msg: "{{ calibre_download_output.src }}" +# +# DEFINED ONLY WHEN /opt/iiab/downloads/calibre-installer.py CHANGES +# - debug: +# msg: "{{ calibre_download_output.backup_file }}" + +# OOPS BAD IDEA: changes in https://github.com/kovidgoyal/calibre/commits/master/setup/linux-installer.py are not sync'd with Calibre releases! +# - name: FORCE AN UPGRADE IF calibre-installer.py HAS CHANGED, IF SO ORIGINAL IS SAVED TO {{ calibre_download_output.backup_file }} +# file: +# path: /usr/bin/calibre-uninstall +# state: absent +# when: calibre_download_output.backup_file is defined + +- name: Check if calibre-installer.py exists in /opt/iiab/downloads + stat: + path: "{{ downloads_dir }}/calibre-installer.py" + register: calib_inst + +- name: Check if calibre-uninstall exists in /usr/bin + stat: + path: "/usr/bin/calibre-uninstall" + register: calib_uninst + +- name: FAIL (force Ansible to exit) IF /opt/iiab/downloads/calibre-installer.py doesn't exist OR needed Internet connection is missing + # meta: end_play + fail: + msg: "{{ downloads_dir }}/calibre-installer.py and an Internet connection are REQUIRED in order to install Calibre!" + when: (not calib_inst.stat.exists) or (not internet_available and not calib_uninst.stat.exists) + +# INSTALL THE LATEST CALIBRE (calibre-server etc) - RUNS IF /usr/bin/calibre-uninstall DOES NOT ALEADY EXIST + +- name: Run calibre-installer.py to install Calibre programs into /usr/bin - MANUALLY REMOVE /usr/bin/calibre-uninstall TO FORCE calibre-installer.py TO REINSTALL/UPGRADE HERE! + shell: "{{ downloads_dir }}/calibre-installer.py >> /dev/null" + args: + creates: /usr/bin/calibre-uninstall + when: internet_available diff --git a/roles/calibre/templates/calibre-serve.service.j2 b/roles/calibre/templates/calibre-serve.service.j2 index 39ad70f01..524845b6e 100644 --- a/roles/calibre/templates/calibre-serve.service.j2 +++ b/roles/calibre/templates/calibre-serve.service.j2 @@ -5,11 +5,8 @@ After=syslog.target network.target local-fs.target [Service] Type=forking PIDFile=/var/run/calibre.pid -{% if is_debuntu %} -ExecStart=/usr/bin/calibre-server --daemonize --pidfile=/var/run/calibre.pid --port={{ calibre_port }} --with-library={{ calibre_dbpath }} -{% else %} -ExecStart=/bin/calibre-server --daemonize --pidfile=/var/run/calibre.pid --port={{ calibre_port }} --with-library={{ calibre_dbpath }} -{% endif %} +ExecStart=/usr/bin/calibre-server --daemonize --log=/var/log/calibre.log --pidfile=/var/run/calibre.pid --port={{ calibre_port }} {{ calibre_dbpath }} + [Install] TimeoutStartSec=900 WantedBy=multi-user.target diff --git a/roles/sugarizer/tasks/main.yml b/roles/sugarizer/tasks/main.yml index 691975f60..363f50e5d 100644 --- a/roles/sugarizer/tasks/main.yml +++ b/roles/sugarizer/tasks/main.yml @@ -96,7 +96,7 @@ - { name: sugarizer } when: not sugarizer_enabled -- name: Add 'sugarizer' to service list in /etc/iiab/iiab.ini +- name: Add 'sugarizer' to service list at /etc/iiab/iiab.ini ini_file: dest: "{{ service_filelist }}" section: sugarizer diff --git a/scripts/calibre-install-latest.sh b/scripts/calibre-install-latest.sh new file mode 100755 index 000000000..69f2e4d43 --- /dev/null +++ b/scripts/calibre-install-latest.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Thanks to Jerry Vonau (https://github.com/jvonau) who made +# this critical breakthrough (Calibre 3.x on Raspbian) possible! + +export DEBIAN_FRONTEND=noninteractive +# Drags in stock desktop dependencies without too much from testing below +apt -y install calibre-bin dirmngr + +# Updates calibre-bin to version 3.10 from testing +apt-key adv --recv-key --keyserver keyserver.ubuntu.com 7638D0442B90D010 +echo "deb http://deb.debian.org/debian testing main" >> /etc/apt/sources.list.d/debian-testing.list +apt update +apt -y install libqt5core5a python-lxml calibre +# Remove last line, safer than: rm /etc/apt/sources.list.d/debian-testing.list +sed -i '$ d' /etc/apt/sources.list.d/debian-testing.list + +# Updates to calibre & calibre-bin to 3.12 from unstable +echo "deb http://deb.debian.org/debian unstable main" >> /etc/apt/sources.list.d/debian-unstable.list +apt update +apt -y install calibre +# Remove last line, safer than: rm /etc/apt/sources.list.d/debian-unstable.list +sed -i '$ d' /etc/apt/sources.list.d/debian-unstable.list + +# Clears the cache of testing and unstable +apt update