Advertisement
Facundo_Adorno

create_fake_DSpace_assetstore

Feb 9th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.04 KB | None | 0 0
  1. #!/bin/sh
  2. # Este scrip descarga un PDF muy pequeño (3,1KB) y lo replica en un assetstore falso según los bitstreams existentes en la BBDD y sus internal_ids.
  3. #A partir de los internal_ids de los bitstreams en DSpace se construye la estructura del assetstore..
  4.  
  5. PGUSER=postgres
  6. PGDATABASE=dspace_sedici_migracion_58
  7. #export PGPASSWORD="root"
  8. ASSETSTORE_DIR=/home/facundo/DSpaceWorkspaces/migracion_sedici_58/install/assetstore
  9. FAKE_BITSTREAM=/tmp/fake.pdf
  10. export_file="/tmp/bitstreams_ids.txt"
  11.  
  12. ###Vars to draw progress bar
  13. count=0
  14. total=
  15. pstr="[=======================================================================]"
  16.  
  17. function draw_progress_bar(){
  18.     count=$(( $count + 1 ))
  19.     pd=$(( $count * 73 / $total ))
  20.     printf "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 / $total) % 10 )) $pstr
  21. }
  22.  
  23.  
  24. if [ ! -d $ASSETSTORE_DIR ]; then
  25.     echo "No existe el directorio $ASSETSTORE_DIR!!!!!!!!"
  26.     exit 1
  27. fi
  28.  
  29. wget -q http://www.tagg.org/pdftest.pdf -O $FAKE_BITSTREAM
  30.  
  31. if [ -d $export_file ]; then
  32.     rm $export_file
  33. fi
  34. #Exportamos todos los internal_ids de los bitstreams a $export_file
  35. psql -U $PGUSER -d $PGDATABASE -c "COPY (SELECT internal_id FROM bitstream) TO '$export_file' (FORMAT TEXT);" > /dev/null
  36.  
  37. total=`wc -l /tmp/bitstreams_ids.txt | cut -d ' ' -f 1`
  38.  
  39. echo "Creando un total de $total bitstreams en el falso repositorio..."
  40. while IFS= read bitstream_internal_id
  41. do
  42.     #El assetstore se compone de 3 niveles 11/22/33/ y en ese directorio se ubica el archivo correspondiente '1122339999999999999999999999999'
  43.     firstsixdigits=${bitstream_internal_id:0:6}
  44.     level_1=${firstsixdigits:0:2}
  45.     level_2=${firstsixdigits:2:2}
  46.     level_3=${firstsixdigits:4:2}
  47.     FINAL_DIR=$ASSETSTORE_DIR/$level_1/$level_2/$level_3/
  48.     mkdir -p $FINAL_DIR
  49.     cp $FAKE_BITSTREAM $FINAL_DIR/$bitstream_internal_id
  50.     draw_progress_bar
  51. done <"$export_file"
  52.  
  53. echo "\n"
  54. echo "Se crearon $total falsos bitstreams en el directorio $ASSETSTORE_DIR con un peso total de `du -chs $ASSETSTORE_DIR`."
  55. echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement