Spaces:
Sleeping
Sleeping
Create start.sh
Browse files
start.sh
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
COLLECTIONS_DIR=/data/collections
|
| 5 |
+
JSON_FILE=/home/default/library.json
|
| 6 |
+
|
| 7 |
+
# Créer le répertoire des collections si absent
|
| 8 |
+
mkdir -p "$COLLECTIONS_DIR"
|
| 9 |
+
|
| 10 |
+
echo "=== Initialisation des collections pywb ==="
|
| 11 |
+
|
| 12 |
+
# Traiter chaque collection définie dans library.json
|
| 13 |
+
if [ -f "$JSON_FILE" ]; then
|
| 14 |
+
python3 -c "
|
| 15 |
+
import json, os, subprocess
|
| 16 |
+
|
| 17 |
+
with open('$JSON_FILE') as f:
|
| 18 |
+
data = json.load(f)
|
| 19 |
+
|
| 20 |
+
for name, url in data.items():
|
| 21 |
+
coll_dir = os.path.join('$COLLECTIONS_DIR', name)
|
| 22 |
+
if not os.path.exists(coll_dir):
|
| 23 |
+
print(f'Création de la collection: {name}')
|
| 24 |
+
subprocess.run(['wb-manager', 'init', name], cwd='$COLLECTIONS_DIR/..')
|
| 25 |
+
|
| 26 |
+
fname = url.split('/')[-1]
|
| 27 |
+
dest = os.path.join(coll_dir, 'archive', fname)
|
| 28 |
+
if not os.path.exists(dest):
|
| 29 |
+
print(f'Téléchargement de {fname} pour la collection {name}…')
|
| 30 |
+
os.makedirs(os.path.dirname(dest), exist_ok=True)
|
| 31 |
+
ret = subprocess.run(['wget', '-c', '-O', dest, url]).returncode
|
| 32 |
+
if ret == 0:
|
| 33 |
+
print(f'Indexation de {fname}…')
|
| 34 |
+
subprocess.run(['wb-manager', 'add', name, dest], cwd='$COLLECTIONS_DIR/..')
|
| 35 |
+
else:
|
| 36 |
+
print(f'Échec du téléchargement de {fname}')
|
| 37 |
+
"
|
| 38 |
+
else
|
| 39 |
+
echo "Aucun fichier library.json trouvé. Aucune collection automatique."
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
echo "=== Démarrage du serveur Wayback ==="
|
| 43 |
+
# wayback écoute par défaut sur 0.0.0.0:8080, on le redirige vers le port 7860
|
| 44 |
+
exec wayback --port 7860 --directory /data
|