***
Wartungsfenster jeden ersten Mittwoch vormittag im Monat
***
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Invenio Utilities
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Center for Research Data Management
Invenio Utilities
Commits
4236d261
Commit
4236d261
authored
4 years ago
by
Moser, Maximilian
Browse files
Options
Downloads
Patches
Plain Diff
Add comments to the upload script code
parent
c17852f5
Branches
Branches containing commit
No related tags found
1 merge request
!1
Updates
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
upload/upload.sh
+25
-0
25 additions, 0 deletions
upload/upload.sh
with
25 additions
and
0 deletions
upload/upload.sh
+
25
−
0
View file @
4236d261
...
@@ -61,24 +61,33 @@ elif [[ -z ${ACCESS_TOKEN} ]]; then
...
@@ -61,24 +61,33 @@ elif [[ -z ${ACCESS_TOKEN} ]]; then
exit
1
exit
1
fi
fi
# check out all supplied positional arguments, and separate them into lists
# of metadata-only records and records with files, for later processing
record_dirs
=()
record_dirs
=()
record_files
=()
record_files
=()
while
[[
$#
-gt
0
]]
;
do
while
[[
$#
-gt
0
]]
;
do
record
=
$1
record
=
$1
if
[[
-f
${
record
}
]]
;
then
if
[[
-f
${
record
}
]]
;
then
# if the argument points to a JSON file, treat it as metadata-only record
jq
.
${
record
}
>
/dev/null
jq
.
${
record
}
>
/dev/null
if
[[
$?
-eq
0
]]
;
then
if
[[
$?
-eq
0
]]
;
then
record_files+
=(
${
record
}
)
record_files+
=(
${
record
}
)
else
else
echo
"not a valid json file:
${
record
}
/metadata.json"
1>&2
echo
"not a valid json file:
${
record
}
/metadata.json"
1>&2
fi
fi
elif
[[
-d
${
record
}
&&
-f
${
record
}
/metadata.json
]]
;
then
elif
[[
-d
${
record
}
&&
-f
${
record
}
/metadata.json
]]
;
then
# if the argument points to a directory containing 'metadata.json',
# treat it as record with files
jq
.
${
record
}
/metadata.json
>
/dev/null
jq
.
${
record
}
/metadata.json
>
/dev/null
if
[[
$?
-eq
0
]]
;
then
if
[[
$?
-eq
0
]]
;
then
record_dirs+
=(
${
record
}
)
record_dirs+
=(
${
record
}
)
else
else
echo
"not a valid json file:
${
record
}
/metadata.json"
1>&2
echo
"not a valid json file:
${
record
}
/metadata.json"
1>&2
fi
fi
else
else
echo
"unknown entity:
${
record
}
"
1>&2
echo
"unknown entity:
${
record
}
"
1>&2
fi
fi
...
@@ -95,7 +104,10 @@ auth_header="Authorization: Bearer ${ACCESS_TOKEN}"
...
@@ -95,7 +104,10 @@ auth_header="Authorization: Bearer ${ACCESS_TOKEN}"
json_header
=
"Content-Type: application/json"
json_header
=
"Content-Type: application/json"
octet_header
=
"Content-Type: application/octet-stream"
octet_header
=
"Content-Type: application/octet-stream"
recids
=()
recids
=()
# upload the collected records with files
for
record
in
${
record_dirs
[@]
}
;
do
for
record
in
${
record_dirs
[@]
}
;
do
# create a new draft, with the specified metadata
recid
=
$(
curl
-sk
-X
POST
-H
"
${
json_header
}
"
-H
"
${
auth_header
}
"
-d
@
${
record
}
/metadata.json
${
base_url
}
/api/records | jq
".id"
)
recid
=
$(
curl
-sk
-X
POST
-H
"
${
json_header
}
"
-H
"
${
auth_header
}
"
-d
@
${
record
}
/metadata.json
${
base_url
}
/api/records | jq
".id"
)
recid
=
${
recid
%\
"}
recid
=
${
recid
%\
"}
recid=
${
recid
#\
"}
recid=
${
recid
#\
"}
...
@@ -104,11 +116,17 @@ for record in ${record_dirs[@]}; do
...
@@ -104,11 +116,17 @@ for record in ${record_dirs[@]}; do
files=()
files=()
file_objects=""
file_objects=""
if [[ -d
${
record
}
/files ]]; then
if [[ -d
${
record
}
/files ]]; then
# check out the content of the 'files/' subdirectory, and collect information
# about the contained files (which are going to be uploaded)
for file in
${
record
}
/files/*; do
for file in
${
record
}
/files/*; do
if [[ ! -f
${
file
}
]]; then
if [[ ! -f
${
file
}
]]; then
echo "
not
a file
:
${
file
}
" 1>&2
echo "
not
a file
:
${
file
}
" 1>&2
continue
continue
fi
fi
# build a list of file names that are going to be uploaded (needed for file upload initialization)
# note: this list is going to start with a comma (','), which has to be considered when using it
file_name=
$(
basename
${
file
}
)
file_name=
$(
basename
${
file
}
)
files+=(
${
file_name
}
)
files+=(
${
file_name
}
)
file_object="
{\
"key
\"
:
\"
${
file_name
}
\"
}"
file_object="
{\
"key
\"
:
\"
${
file_name
}
\"
}"
...
@@ -116,30 +134,37 @@ for record in ${record_dirs[@]}; do
...
@@ -116,30 +134,37 @@ for record in ${record_dirs[@]}; do
done
done
fi
fi
# initialize the record
's files (send the list of files that are expected to be uploaded)
curl -sk -X POST -H "${json_header}" -H "${auth_header}" -d "[${file_objects:1}]" ${base_url}/api/records/${recid}/draft/files > /dev/null
curl -sk -X POST -H "${json_header}" -H "${auth_header}" -d "[${file_objects:1}]" ${base_url}/api/records/${recid}/draft/files > /dev/null
# upload each file'
s
content, and finalize (commit) the upload
for file in
${
files
[@]
}
; do
for file in
${
files
[@]
}
; do
file_base_url=
${
base_url
}
/api/records/
${
recid
}
/draft/files/
${
file
}
file_base_url=
${
base_url
}
/api/records/
${
recid
}
/draft/files/
${
file
}
curl -sk -X PUT -H
"
${
octet_header
}
"
-H
"
${
auth_header
}
"
--upload-file
${
record
}
/files/
${
file
}
${
file_base_url
}
/content > /dev/null
curl -sk -X PUT -H
"
${
octet_header
}
"
-H
"
${
auth_header
}
"
--upload-file
${
record
}
/files/
${
file
}
${
file_base_url
}
/content > /dev/null
curl -sk -X POST -H
"
${
auth_header
}
"
${
file_base_url
}
/commit > /dev/null
curl -sk -X POST -H
"
${
auth_header
}
"
${
file_base_url
}
/commit > /dev/null
done
done
# if not specifically requested otherwise, publish the newly created draft
if [[
$publish
-gt 0 ]]; then
if [[
$publish
-gt 0 ]]; then
curl -sk -X POST -H
"
${
auth_header
}
"
${
base_url
}
/api/records/
${
recid
}
/draft/actions/publish > /dev/null
curl -sk -X POST -H
"
${
auth_header
}
"
${
base_url
}
/api/records/
${
recid
}
/draft/actions/publish > /dev/null
fi
fi
done
done
# upload the collected metadata-only records
for record in
${
record_files
[@]
}
; do
for record in
${
record_files
[@]
}
; do
# create a new draft, with the specified metadata
recid=
$(
curl
-sk
-X
POST
-H
"
${
json_header
}
"
-H
"
${
auth_header
}
"
-d
@
${
record
}
${
base_url
}
/api/records | jq
".id"
)
recid=
$(
curl
-sk
-X
POST
-H
"
${
json_header
}
"
-H
"
${
auth_header
}
"
-d
@
${
record
}
${
base_url
}
/api/records | jq
".id"
)
recid=
${
recid
%\
"}
recid=
${
recid
%\
"}
recid=
${
recid
#\
"}
recid=
${
recid
#\
"}
recids+=(
${
recid
}
)
recids+=(
${
recid
}
)
# if not specifically requested otherwise, publish the newly created draft
if [[
$publish
-gt 0 ]]; then
if [[
$publish
-gt 0 ]]; then
curl -sk -X POST -H "
${
auth_header
}
"
${
base_url
}
/api/records/
${
recid
}
/draft/actions/publish > /dev/null
curl -sk -X POST -H "
${
auth_header
}
"
${
base_url
}
/api/records/
${
recid
}
/draft/actions/publish > /dev/null
fi
fi
done
done
# print the recid of each created record
for recid in
${
recids
[@]
}
; do
for recid in
${
recids
[@]
}
; do
echo
${
recid
}
echo
${
recid
}
done
done
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment