File size: 1,478 Bytes
daedf4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
#!/bin/bash
set -e

COLLECTIONS_DIR=/data/collections
JSON_FILE=/home/default/library.json

# Créer le répertoire des collections si absent
mkdir -p "$COLLECTIONS_DIR"

echo "=== Initialisation des collections pywb ==="

# Traiter chaque collection définie dans library.json
if [ -f "$JSON_FILE" ]; then
    python3 -c "
import json, os, subprocess

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

for name, url in data.items():
    coll_dir = os.path.join('$COLLECTIONS_DIR', name)
    if not os.path.exists(coll_dir):
        print(f'Création de la collection: {name}')
        subprocess.run(['wb-manager', 'init', name], cwd='$COLLECTIONS_DIR/..')
    
    fname = url.split('/')[-1]
    dest = os.path.join(coll_dir, 'archive', fname)
    if not os.path.exists(dest):
        print(f'Téléchargement de {fname} pour la collection {name}…')
        os.makedirs(os.path.dirname(dest), exist_ok=True)
        ret = subprocess.run(['wget', '-c', '-O', dest, url]).returncode
        if ret == 0:
            print(f'Indexation de {fname}…')
            subprocess.run(['wb-manager', 'add', name, dest], cwd='$COLLECTIONS_DIR/..')
        else:
            print(f'Échec du téléchargement de {fname}')
"
else
    echo "Aucun fichier library.json trouvé. Aucune collection automatique."
fi

echo "=== Démarrage du serveur Wayback ==="
# wayback écoute par défaut sur 0.0.0.0:8080, on le redirige vers le port 7860
exec wayback --port 7860 --directory /data