mirror of
https://gh.wpcy.net/https://github.com/aspirepress/AspireSync.git
synced 2026-05-30 23:44:03 +08:00
48 lines
1 KiB
Bash
Executable file
48 lines
1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#
|
|
# EXAMPLE: bin/console sync:meta:dump:plugins --after='-1 hour' | meta/bin/push-to-aspirecloud
|
|
#
|
|
|
|
. $(dirname $0)/prelude.bash
|
|
|
|
URL=${ASPIRECLOUD_ADMIN_API_URL:?variable not defined}
|
|
KEY=${ASPIRECLOUD_ADMIN_API_KEY:?variable not defined}
|
|
|
|
echo "Pushing to $URL"
|
|
|
|
CHUNK_SIZE=${CHUNK_SIZE:-100} # values > 100 are likely to run into POST size limits
|
|
|
|
CURL_ARGS=${CURL_ARGS:-'--compressed'}
|
|
|
|
function main() {
|
|
local buffer=$(mktemp)
|
|
trap 'rm -f "$buffer"' EXIT
|
|
|
|
local count=0
|
|
|
|
while IFS= read -r line || [[ -n $line ]]; do
|
|
echo "$line" >> $buffer
|
|
(( count += 1 ))
|
|
echo -e -n "\ruploading $count ... "
|
|
[[ $(wc -l < $buffer) -ge $CHUNK_SIZE ]] && upload $buffer
|
|
done
|
|
|
|
upload $buffer
|
|
|
|
echo "done"
|
|
}
|
|
|
|
function upload() {
|
|
buffer=$1
|
|
[[ -s $buffer ]] && curl --silent -XPOST \
|
|
-H "Authorization: Bearer $KEY" \
|
|
-H 'Content-Type: application/nljson' \
|
|
-H 'Accept: application/json' \
|
|
--data-binary @"$buffer" \
|
|
$CURL_ARGS \
|
|
"$URL/v1/import" > /dev/null
|
|
cp /dev/null $buffer
|
|
}
|
|
|
|
main "$@"
|