1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-15 04:32:11 +00:00
iiab/roles/calibre-web/tasks/install.yml

205 lines
8.9 KiB
YAML

# Or try 'iiab-update -f' for a more rapid upgrade of IIAB Calibre-Web:
#
# https://wiki.iiab.io/go/FAQ#Can_I_upgrade_IIAB_software%3F
# https://github.com/iiab/calibre-web/wiki#upgrading
# https://github.com/iiab/iiab/blob/master/scripts/iiab-update
# https://github.com/iiab/iiab/tree/master/roles/calibre-web#upgrading
- name: Record (initial) disk space used
shell: df -B1 --output=used / | tail -1
register: df1
- name: Stop 'calibre-web' systemd service for safety (RED ERROR CAN BE IGNORED!)
systemd:
name: calibre-web
state: stopped
ignore_errors: True # Shows red errors, and continue...
#failed_when: False # Hides red errors, and continue...
# Official upstream instructions:
# apt install python3-pip python3-venv
# https://github.com/janeczku/calibre-web/wiki/Manual-installation
- name: "Install packages: imagemagick, python3-netifaces"
package:
name:
- imagemagick
#- python3-cryptography # Was needed on Raspberry Pi OS (SEE iiab/calibre-web#260, janeczku/calibre-web#3183)
- python3-netifaces
state: present
# https://github.com/iiab/iiab/pull/3496#issuecomment-1475094542
#- name: "Install packages: python3-dev, gcc to compile 'netifaces'"
# package:
# name:
# - python3-dev # header files
# - gcc # compiler
# state: present
# when: python_version is version('3.10', '>=')
- name: Allow ImageMagick to read PDFs, per /etc/ImageMagick-6/policy.xml, to create book cover thumbnails
lineinfile:
path: /etc/ImageMagick-6/policy.xml
regexp: '<policy domain="coder" rights="none" pattern="PDF" />'
backrefs: yes
line: ' <policy domain="coder" rights="read" pattern="PDF" />'
state: present
- name: "Create 3 Calibre-Web folders to store data and config files: {{ calibreweb_home }}, {{ calibreweb_venv_path }}, {{ calibreweb_config }} (all set to {{ calibreweb_user }}:{{ apache_user }}) (default to 0755)"
file:
state: directory
path: "{{ item }}"
owner: "{{ calibreweb_user }}" # root
group: "{{ apache_user }}" # www-data on debuntu
with_items:
- "{{ calibreweb_home }}" # /library/calibre-web
- "{{ calibreweb_config }}" # /library/calibre-web/config
# FYI since May 2021, Calibre-Web (major releases) can be installed with pip:
# https://pypi.org/project/calibreweb/
# https://github.com/janeczku/calibre-web/issues/456
# https://github.com/janeczku/calibre-web/issues/677
# https://github.com/janeczku/calibre-web/pull/927
# https://github.com/janeczku/calibre-web/pull/1459
- name: "Remove previous virtual environment {{ calibreweb_venv_path }} -- if 'calibreweb_venv_wipe: True'"
file:
path: "{{ calibreweb_venv_path }}" # /usr/local/calibre-web-py3
state: absent
when: calibreweb_venv_wipe
- name: Does {{ calibreweb_venv_path }} exist?
stat:
path: "{{ calibreweb_venv_path }}"
register: calibreweb_venv
- name: git clone Calibre-Web ({{ calibreweb_version }}) from {{ calibreweb_repo_url }} to {{ calibreweb_venv_path }} (~122 MB initially, ~191+ or ~203+ MB later) -- if {{ calibreweb_venv_path }} doesns't exist
git:
repo: "{{ calibreweb_repo_url }}" # e.g. https://github.com/iiab/calibre-web or https://github.com/janeczku/calibre-web
dest: "{{ calibreweb_venv_path }}"
#force: True # CLAIM: "If true, any modified files in the working repository will be discarded" -- REALITY: even if `force: no`, Ansible destructively reclones (also removing all test branch commits etc!) -- unless a git credential is provided to Ansible?
#depth: 1 # 2023-11-04: Full clone for now, to help @deldesir & wider community testing
version: "{{ calibreweb_version }}" # e.g. master, 0.6.22
when: not calibreweb_venv.stat.exists
- name: cd {{ calibreweb_venv_path }} ; git pull {{ calibreweb_repo_url }} {{ calibreweb_version }} --no-rebase --no-edit -- if {{ calibreweb_venv_path }} exists
command: git pull "{{ calibreweb_repo_url }}" "{{ calibreweb_version }}" --no-rebase --no-edit
args:
chdir: "{{ calibreweb_venv_path }}"
when: calibreweb_venv.stat.exists
- debug:
msg:
- "NEED BETTER/EXPERIMENTAL YouTube SCRAPING? RUN THE NEXT LINE -- for the latest yt-dlp 'nightly' release:"
- sudo pipx inject --pip-args='--upgrade --pre' -f xklb yt-dlp[default]
- name: If Calibre-Web is being enhanced with audio/video "books" too, install/upgrade additional prereqs -- SEE https://github.com/iiab/calibre-web/wiki
shell: |
if [ -f {{ calibreweb_venv_path }}/scripts/lb-wrapper ]; then
apt install ffmpeg pipx -y
if lb --version; then
pipx reinstall xklb
else
pipx install xklb
ln -sf /root/.local/bin/lb /usr/local/bin/lb
if [ -f /root/.local/share/pipx/venvs/xklb/bin/yt-dlp ]; then
ln -sf /root/.local/share/pipx/venvs/xklb/bin/yt-dlp /usr/local/bin/yt-dlp
elif [ -f /root/.local/pipx/venvs/xklb/bin/yt-dlp ]; then
ln -sf /root/.local/pipx/venvs/xklb/bin/yt-dlp /usr/local/bin/yt-dlp
else
echo "ERROR: yt-dlp NOT FOUND"
fi
fi
# NEED BETTER/EXPERIMENTAL YouTube SCRAPING? UNCOMMENT THE NEXT LINE -- for the latest yt-dlp "nightly" release:
# pipx inject --pip-args="--upgrade --pre" -f xklb yt-dlp[default]
#
# https://github.com/yt-dlp/yt-dlp-nightly-builds/releases
# https://pypi.org/project/yt-dlp/#history
cp {{ calibreweb_venv_path }}/scripts/lb-wrapper /usr/local/bin/
chmod a+x /usr/local/bin/lb-wrapper
fi
- name: Download Calibre-Web dependencies from 'requirements.txt' into python3 virtual environment {{ calibreweb_venv_path }}
pip:
requirements: "{{ calibreweb_venv_path }}/requirements.txt"
virtualenv: "{{ calibreweb_venv_path }}" # /usr/local/calibre-web-py3
#virtualenv_site_packages: no
virtualenv_command: python3 -m venv --system-site-packages {{ calibreweb_venv_path }}
extra_args: --prefer-binary # 2023-10-01: Lifesaver when recent wheels (e.g. piwheels.org) are inevitably not yet built! SEE #3560
# 2023-10-11: RasPiOS Bookworm doc for Python with venv (PEP 668 now enforced!)
# https://www.raspberrypi.com/documentation/computers/os.html#use-python-on-a-raspberry-pi
# https://www.raspberrypi.com/documentation/computers/os.html#install-python-packages-using-apt
# https://www.raspberrypi.com/documentation/computers/os.html#install-python-libraries-using-pip
# VIRTUALENV EXAMPLE COMMANDS:
# python3 -m venv /usr/local/calibre-web-py3 (create venv)
# cd /usr/local/calibre-web-py3
# . bin/activate (or 'source bin/activate' -- this prepends '/usr/local/calibre-web-py3/bin' to yr PATH)
# python3 -m pip list ('pip list' sufficient *IF* path set above!)
# python3 -m pip freeze > /tmp/requirements.txt
# python3 -m pip install -r requirements.txt
# deactivate
# https://pip.pypa.io/en/stable/user_guide/#requirements-files
# https://pip.pypa.io/en/latest/reference/requirements-file-format/
- name: Install /etc/systemd/system/calibre-web.service from template
template:
src: calibre-web.service.j2
dest: /etc/systemd/system/calibre-web.service
- name: Does /library/calibre-web/metadata.db exist?
stat:
path: /library/calibre-web/metadata.db
register: metadatadb
- name: Provision/Copy both default metadata files (metadata.db, metadata_db_prefs_backup.json) into {{ calibreweb_home }} IF metadata.db did not exist
copy:
src: "{{ item }}"
dest: "{{ calibreweb_home }}" # /library/calibre-web
owner: "{{ calibreweb_user }}" # root
group: "{{ apache_user }}" # www-data on debuntu
backup: yes
with_items:
- roles/calibre-web/files/metadata.db
- roles/calibre-web/files/metadata_db_prefs_backup.json
when: not metadatadb.stat.exists
- name: Does /library/calibre-web/config/app.db exist?
stat:
path: /library/calibre-web/config/app.db
register: appdb
- name: Provision/Copy default admin settings to {{ calibreweb_config }}/app.db IF it did not exist
copy:
src: roles/calibre-web/files/app.db
dest: "{{ calibreweb_config }}" # /library/calibre-web/config
owner: "{{ calibreweb_user }}" # root
group: "{{ apache_user }}" # www-data on debuntu
backup: yes
when: not appdb.stat.exists
# RECORD Calibre-Web AS INSTALLED
- name: Record (final) disk space used
shell: df -B1 --output=used / | tail -1
register: df2
- name: Add 'calibreweb_disk_usage = {{ df2.stdout|int - df1.stdout|int }}' to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section: calibre-web
option: calibreweb_disk_usage
value: "{{ df2.stdout|int - df1.stdout|int }}"
- name: "Set 'calibreweb_installed: True'"
set_fact:
calibreweb_installed: True
- name: "Add 'calibreweb_installed: True' to {{ iiab_state_file }}"
lineinfile:
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp: '^calibreweb_installed'
line: 'calibreweb_installed: True'