-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulkupload_bash.sh
More file actions
executable file
·73 lines (60 loc) · 2.32 KB
/
Copy pathbulkupload_bash.sh
File metadata and controls
executable file
·73 lines (60 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
echo "🚀 Starting bulkupload_bash.sh"
API_TOKEN="YOUR API TOKEN"
HOSTNAME="https://demo.borealisdata.ca"
DATAVERSE_ALIAS="YOUR COLLECTION ALIAS"
DIRECTORY="YOUR LOCAL DIRECTORY"
WAIT=0
CONTACT_EMAIL="${CONTACT_EMAIL:-youremail@example.ca}"
add_dataset_contact_email() {
local metadata_file="$1"
local email="$2"
if [ ! -f "$metadata_file" ]; then
echo "❌ Metadata file not found: $metadata_file"
return 1
fi
local tmp_file
tmp_file=$(mktemp)
jq --arg email "$email" '
.datasetVersion.metadataBlocks.citation.fields |=
map(
if .typeName == "datasetContact" and .typeClass == "compound" then
.value |= map(
if has("datasetContactEmail") then
.
else
. + {"datasetContactEmail": {"typeName": "datasetContactEmail", "multiple": false, "typeClass": "primitive", "value": $email}}
end
)
else
.
end
)
' "$metadata_file" > "$tmp_file" && mv "$tmp_file" "$metadata_file"
}
for datasetDir in "$DIRECTORY"/* ; do
echo "Preparing $datasetDir ..."
if ! add_dataset_contact_email "$datasetDir/metadata.json" "$CONTACT_EMAIL"; then
echo "⚠️ Skipping $datasetDir due to metadata update failure"
continue
fi
echo "Creating the dataset from $datasetDir ..."
OUTPUT=$(jq 'del(.datasetVersion.files)' "$datasetDir/metadata.json" | \
curl -s -X POST -H "Content-type:application/json" \
-d @- "$HOSTNAME/api/dataverses/$DATAVERSE_ALIAS/datasets/?key=$API_TOKEN")
echo "Response: $OUTPUT"
DOI=$(echo "$OUTPUT" | grep -o '"persistentId":"[^"]*"' | cut -d'"' -f4)
echo "Extracted DOI: $DOI"
if [ -z "$DOI" ]; then
echo "❌ No DOI found — skipping file upload for $datasetDir"
continue
fi
filesize=$(du -k "$datasetDir/files.zip" 2>/dev/null | cut -f1)
echo "Filesize is $filesize KB — uploading..."
curl -u "$API_TOKEN": --data-binary @"$datasetDir/files.zip" \
-H "Content-Disposition: filename=files.zip" \
-H "Content-Type: application/zip" \
-H "Packaging: http://purl.org/net/sword/package/SimpleZip" \
"$HOSTNAME/dvn/api/data-deposit/v1.1/swordv2/edit-media/study/$DOI"
echo "Done with $datasetDir"
echo "--------------------------------"
done