Spaces:
Sleeping
Sleeping
| 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" |