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