File size: 1,146 Bytes
1e185bc
 
 
 
 
 
86e8308
1e185bc
 
 
86e8308
1e185bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86e8308
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
set -e

LIBRARY_DIR=/data/calibre-library
JSON_FILE=/defaults/library.json

# Création du dossier et lien symbolique
mkdir -p "$LIBRARY_DIR"
ln -sfn "$LIBRARY_DIR" /books

# Téléchargement et importation des ebooks (exécuté en root)
if [ -f "$JSON_FILE" ]; then
    python3 -c "
import json, os, subprocess

with open('$JSON_FILE') as f:
    data = json.load(f)

for title, url in data.items():
    dest = '/books/' + title + '.epub'
    if os.path.exists(dest):
        print(f'{title} déjà présent, ignoré.')
        continue
    print(f'Téléchargement de {title}…')
    ret = subprocess.run(['wget', '--tries=3', '--retry-connrefused', '-c', '-O', dest, url]).returncode
    if ret == 0:
        print(f'Importation dans Calibre…')
        subprocess.run(['calibredb', 'add', '--library-path=/books', dest])
    else:
        print(f'Échec du téléchargement de {title}')
"
else
    echo "library.json introuvable, aucun ebook téléchargé automatiquement."
fi

# === CORRECTION DES PERMISSIONS ===
# L'utilisateur abc (UID 911, GID 911) doit pouvoir écrire dans la bibliothèque.
chown -R 911:911 "$LIBRARY_DIR"