...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/bin/sh # # This is pseudocode which provides an example for how ingesting a bag might look # when scripted. It will likely be revised before the production release of 3.0.0 # to actually work. ################################################################################# BAGS="test-bag-0" MANIFEST="manifest-sha256.txt" TAGMANIFEST="tagmanifest-sha256.txt" BAG_JSON="{}" STAGING_JSON="{}"'{"name":"scripted-bag-0", "depositor": "script-depositor", "size": 1024, "totalFiles": 10, "storageRegion": 1, "location": "script-depositor/scripted-bag-0"}' STAGING_JSON='{"location": "script-depositor/scripted-bag-0", "validationFile": "/tagmanifest-sha256.txt", "storageRegion": 1, "totalFiles": 10, "size": 1024, "storageUnit": "B"}' INGEST_USER="ingest" INGEST_PASSWORD="secret" INGEST_BAG_CREATE="http://localhost:8080/api/bags" INGEST_FILE_CREATE="http://localhost:8080/api/bags/{id}/files" INGEST_STAGING_CREATE="http://localhost:8080/api/bags{id}/staging/BAG" generate_csv() { for bag in $BAGS; do current_manifest="$bag/$MANIFEST" current_tagmanifest="$bag/$TAGMANIFEST" awk -v bag="$bag" 'BEGIN { printf "FILENAME,SIZE,FIXITY_VALUE,FIXITY_ALGORITHM\n" } { printf "\"" $2 "\"," system("find " bag "/" $2 " -printf '%s'") printf "," printf $1 ",SHA-256\n" }' $current_tagmanifest $current_manifest > "$bag".csv tagsum=$(sha256sum $current_tagmanifest | cut -c -64) tagsize=$(find $current_tagmanifest -printf '%s') echo "\"$TAGMANIFEST\",$tagsize,$tagsum,SHA-256" >> "$bag".csv gzip -c "$bag".csv > "$bag".csv.gz echo -n "$bag csv: " find "${bag}.csv" -printf '%s\n' done } # generate a csv file generate_csv(); # register the bag, files, and staging curl --user ${INGEST_USER}:${INGEST_PASSWORD} --header "Content-Type: application/json" --data '${BAG_JSON}' ${INGEST_BAG_CREATE} # the bag id needs to be retrieved and injected into the next 2 calls curl --user ${INGEST_USER}:${INGEST_PASSWORD} -F "file=@${bag}.csv;type=text/csv" ${INGEST_FILE_CREATE} curl --user ${INGEST_USER}:${INGEST_PASSWORD} --header "Content-Type: application/json" --data '${STAGING_JSON}' ${INGEST_STAGING_CREATE} |
...