Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # 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.
- #A partir de los internal_ids de los bitstreams en DSpace se construye la estructura del assetstore..
- PGUSER=postgres
- PGDATABASE=dspace_sedici_migracion_58
- #export PGPASSWORD="root"
- ASSETSTORE_DIR=/home/facundo/DSpaceWorkspaces/migracion_sedici_58/install/assetstore
- FAKE_BITSTREAM=/tmp/fake.pdf
- export_file="/tmp/bitstreams_ids.txt"
- ###Vars to draw progress bar
- count=0
- total=
- pstr="[=======================================================================]"
- function draw_progress_bar(){
- count=$(( $count + 1 ))
- pd=$(( $count * 73 / $total ))
- printf "\r%3d.%1d%% %.${pd}s" $(( $count * 100 / $total )) $(( ($count * 1000 / $total) % 10 )) $pstr
- }
- if [ ! -d $ASSETSTORE_DIR ]; then
- echo "No existe el directorio $ASSETSTORE_DIR!!!!!!!!"
- exit 1
- fi
- wget -q http://www.tagg.org/pdftest.pdf -O $FAKE_BITSTREAM
- if [ -d $export_file ]; then
- rm $export_file
- fi
- #Exportamos todos los internal_ids de los bitstreams a $export_file
- psql -U $PGUSER -d $PGDATABASE -c "COPY (SELECT internal_id FROM bitstream) TO '$export_file' (FORMAT TEXT);" > /dev/null
- total=`wc -l /tmp/bitstreams_ids.txt | cut -d ' ' -f 1`
- echo "Creando un total de $total bitstreams en el falso repositorio..."
- while IFS= read bitstream_internal_id
- do
- #El assetstore se compone de 3 niveles 11/22/33/ y en ese directorio se ubica el archivo correspondiente '1122339999999999999999999999999'
- firstsixdigits=${bitstream_internal_id:0:6}
- level_1=${firstsixdigits:0:2}
- level_2=${firstsixdigits:2:2}
- level_3=${firstsixdigits:4:2}
- FINAL_DIR=$ASSETSTORE_DIR/$level_1/$level_2/$level_3/
- mkdir -p $FINAL_DIR
- cp $FAKE_BITSTREAM $FINAL_DIR/$bitstream_internal_id
- draw_progress_bar
- done <"$export_file"
- echo "\n"
- echo "Se crearon $total falsos bitstreams en el directorio $ASSETSTORE_DIR con un peso total de `du -chs $ASSETSTORE_DIR`."
- echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement