madiba-elate commited on
Commit
1e185bc
·
verified ·
1 Parent(s): d1cca3c

Create start.sh

Browse files
Files changed (1) hide show
  1. start.sh +37 -0
start.sh ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ LIBRARY_DIR=/data/calibre-library
5
+ JSON_FILE=/defaults/library.json
6
+
7
+ # Création du répertoire et lien symbolique pour que Calibre-Web trouve la bibliothèque
8
+ mkdir -p "$LIBRARY_DIR"
9
+ ln -sfn "$LIBRARY_DIR" /books
10
+
11
+ # Téléchargement et importation des ebooks
12
+ if [ -f "$JSON_FILE" ]; then
13
+ python3 -c "
14
+ import json, os, subprocess
15
+
16
+ with open('$JSON_FILE') as f:
17
+ data = json.load(f)
18
+
19
+ for title, url in data.items():
20
+ dest = '/books/' + title + '.epub'
21
+ if os.path.exists(dest):
22
+ print(f'{title} déjà présent, ignoré.')
23
+ continue
24
+ print(f'Téléchargement de {title}…')
25
+ ret = subprocess.run(['wget', '--tries=3', '--retry-connrefused', '-c', '-O', dest, url]).returncode
26
+ if ret == 0:
27
+ print(f'Importation dans Calibre…')
28
+ subprocess.run(['calibredb', 'add', '--library-path=/books', dest])
29
+ else:
30
+ print(f'Échec du téléchargement de {title}')
31
+ "
32
+ else
33
+ echo "library.json introuvable, aucun ebook téléchargé automatiquement."
34
+ fi
35
+
36
+ # Indique à Calibre-Web d'utiliser le port 7860
37
+ export CALIBRE_PORT=7860