Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandbox #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ export ZENODO_TOKEN=[Zenodo access token]
5. in the browser, copy the deposition id (e.g., in ```https://zenodo.org/deposit/12345``` , 12345 is the deposition id)
6. in terminal and upload a file using
```bash
./zenodo_upload.sh [deposition id] [filename]
./zenodo_upload.sh [-s] <deposition id> <filename>
```
Including option `-s` will upload the file to ```https://sandbox.zenodo.org/deposit/12346```instead.
7. on completion, you should see something like:
```shell
+ curl ...
Expand Down
24 changes: 20 additions & 4 deletions zenodo_upload.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
#!/bin/bash
# Upload big files to Zenodo.
#
# usage: ./zenodo_upload.sh [deposition id] [filename]
#
# usage: ./zenodo_upload.sh [-s] <deposition id> <filename>
# -s ... upload to zenodo sandbox

set -e

SBSTR=""

while getopts "s" opt; do
case $opt in
"s") echo "running in sandbox mode" >&2
SBSTR="sandbox."
;;
*) echo "Error: invalid option" >&2
exit 1
;;
esac
done
# reset option index for positional arguments later
shift "$(( OPTIND - 1 ))"


# strip deposition url prefix if provided; see https://github.com/jhpoelen/zenodo-upload/issues/2#issuecomment-797657717
DEPOSITION=$( echo $1 | sed 's+^http[s]*://zenodo.org/deposit/++g' )
DEPOSITION=$( echo $1 | sed "s+^http[s]*://${SBSTR}zenodo.org/deposit/++g" )
FILEPATH="$2"
FILENAME=$(echo $FILEPATH | sed 's+.*/++g')

BUCKET=$(curl https://zenodo.org/api/deposit/depositions/"$DEPOSITION"?access_token="$ZENODO_TOKEN" | jq --raw-output .links.bucket)
BUCKET=$(curl https://${SBSTR}zenodo.org/api/deposit/depositions/"$DEPOSITION"?access_token="$ZENODO_TOKEN" | jq --raw-output .links.bucket)

curl --progress-bar -o /dev/null --upload-file "$FILEPATH" $BUCKET/"$FILENAME"?access_token="$ZENODO_TOKEN"