Created
December 20, 2025 01:41
-
-
Save hanyuwei70/fe0997101e53f999dd838e5b38cbaf3d to your computer and use it in GitHub Desktop.
Upload shell script for Seafile 12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Ref: https://extgit.isec.tugraz.at/con/vm-provisioning/-/blob/master/ci/seafile-upload.sh | |
| # Seafile Version: 12.0.14 | |
| set -u | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 <SHARE_URL> <FILE>" | |
| echo "Example: $0 https://seafile.iaik.tugraz.at/u/d/xxx/ archive.tar.gz" | |
| exit 1 | |
| fi | |
| SHARE_URL=$1 | |
| FILEPATH=$(realpath $2) | |
| FILENAME=$(basename ${FILEPATH}) | |
| DOMAIN=$(echo ${SHARE_URL} | grep -Po ".+(?=/u/d.+)" ) | |
| SHARE_ID=$(echo ${SHARE_URL} | grep -Po "(?<=u/d/).+(?=/)" ) | |
| # First request to extract the path. | |
| UPLOAD_PATH=$(curl -s ${SHARE_URL} | grep -Po "(?<=path: \").+?(?=\")") | |
| # Second request to get an upload url. | |
| UPLOAD_URL=$(curl -s "${DOMAIN}/api/v2.1/upload-links/${SHARE_ID}/upload/" -H 'Accept: application/json' | grep -Po "http.+(?=[\'\"])") | |
| # Third request to perform the actual upload. | |
| RESPONSE=$(curl "${UPLOAD_URL}?ret-json=1" -F file=@${FILEPATH} -F filename=${FILENAME} -F parent_dir="${UPLOAD_PATH}") | |
| if [ $? -ne 0 ] | |
| then | |
| exit 1 | |
| fi | |
| # Check for an error response. | |
| echo ${RESPONSE} | grep -q error | |
| if [ $? -eq 0 ] | |
| then | |
| echo ${RESPONSE} | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment