Project

Profile

Help

Issue #5087 ยป test-chunk.sh

jcabrera, 07/05/2019 11:48 AM

 
#!/bin/bash

pkg=$1

PORT=dev-pulp-server.ptci.dev:24817

size=$(ls -l $pkg | cut -d ' ' -f5)
echo "get sha256 sum"
sha256=$(sha256sum $pkg | cut -d ' ' -f1)
echo sha256=$sha256
echo "Split file"
split --bytes=300M $pkg chunk

export UPLOAD=$(http POST $PORT/pulp/api/v3/uploads/ size=$size | jq -r '._href')
echo $UPLOAD
n=0
# get chunck files infos
for f in chunk*; do
fname[$n]=$f
fsize[$n]=$(ls -l $f | cut -d ' ' -f5)
if [ $n -eq 0 ]; then
bindex[$n]=0
else
bindex[$n]=$((${eindex[$(($n-1))]} + 1))
fi
eindex[$n]=$((fsize[$n] + ${bindex[$n]} - 1))
n=$(($n+1))
done

# upload chuncks
for n in ${!fname[*]}; do
echo "Uploading: ${fname[$n]} ${bindex[$n]}-${eindex[$n]}"
http --form PUT $PORT$UPLOAD file@${fname[$n]} "Content-Range:bytes ${bindex[$n]}-${eindex[$n]}/*"
done

echo "Ending Upload"
http PUT $PORT${UPLOAD}commit/ sha256=$sha256
echo "Creating artifact"
http POST $PORT/pulp/api/v3/artifacts/ upload=$UPLOAD

# clean
for n in ${!fname[*]}; do
rm -f ${fname[$n]}
done
    (1-1/1)