From ce38bccadd5f488b7b35c159fd72fcc12d4f4181 Mon Sep 17 00:00:00 2001 From: LukasRier <45269525+LukasRier@users.noreply.github.com> Date: Mon, 12 Dec 2022 11:36:49 +0000 Subject: [PATCH 1/5] Add sandbox option to usage string add option [-sb] to indicate user is uploading to a zenodo repository in sandbox mode. Positional arguments are not optional and therefore indicated using < > --- zenodo_upload.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenodo_upload.sh b/zenodo_upload.sh index 15adfba..2f017d2 100755 --- a/zenodo_upload.sh +++ b/zenodo_upload.sh @@ -1,8 +1,8 @@ #!/bin/bash # Upload big files to Zenodo. # -# usage: ./zenodo_upload.sh [deposition id] [filename] -# +# usage: ./zenodo_upload.sh [-sb] +# -sb ... upload to zenodo sandbox set -e From bf3c37f6ded394ddef90a06ad2e8ac211ec30fc9 Mon Sep 17 00:00:00 2001 From: LukasRier <45269525+LukasRier@users.noreply.github.com> Date: Mon, 12 Dec 2022 12:10:29 +0000 Subject: [PATCH 2/5] Rename sandbox option to s --- zenodo_upload.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenodo_upload.sh b/zenodo_upload.sh index 2f017d2..3dd3e6a 100755 --- a/zenodo_upload.sh +++ b/zenodo_upload.sh @@ -1,8 +1,8 @@ #!/bin/bash # Upload big files to Zenodo. # -# usage: ./zenodo_upload.sh [-sb] -# -sb ... upload to zenodo sandbox +# usage: ./zenodo_upload.sh [-s] +# -s ... upload to zenodo sandbox set -e From 2f3b87905e7528938317a6fd380ca476b11343ec Mon Sep 17 00:00:00 2001 From: LukasRier <45269525+LukasRier@users.noreply.github.com> Date: Mon, 12 Dec 2022 12:12:11 +0000 Subject: [PATCH 3/5] Option handling Initialise sandbox string, check for invalid options and reset option index for positional arguments later. --- zenodo_upload.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/zenodo_upload.sh b/zenodo_upload.sh index 3dd3e6a..8ddce42 100755 --- a/zenodo_upload.sh +++ b/zenodo_upload.sh @@ -6,6 +6,22 @@ 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' ) FILEPATH="$2" From f3bb33d82b5b4e0502ae67f2a83f6082addee9cf Mon Sep 17 00:00:00 2001 From: LukasRier <45269525+LukasRier@users.noreply.github.com> Date: Mon, 12 Dec 2022 12:14:11 +0000 Subject: [PATCH 4/5] Include sandbox string in deposition and bucket Inlcudes sandbox string (SBSTR) in relevant urls. sandbox.zenodo... if -s is set or leaves the urls unchanged if -s is not set --- zenodo_upload.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zenodo_upload.sh b/zenodo_upload.sh index 8ddce42..7b3583a 100755 --- a/zenodo_upload.sh +++ b/zenodo_upload.sh @@ -23,10 +23,10 @@ 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" From cd4d156506d85adec64a1c67f5de5f85023ef42c Mon Sep 17 00:00:00 2001 From: LukasRier <45269525+LukasRier@users.noreply.github.com> Date: Mon, 12 Dec 2022 12:37:24 +0000 Subject: [PATCH 5/5] Update to include sandbox option --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e196d1..15371aa 100644 --- a/README.md +++ b/README.md @@ -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] ``` +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 ...