Project

Profile

Help

Issue #5087 ยป test-chunk.sh

jcabrera, 07/05/2019 11:48 AM

 
1
#!/bin/bash
2

    
3
pkg=$1
4

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

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

    
14
export UPLOAD=$(http POST $PORT/pulp/api/v3/uploads/ size=$size | jq -r '._href')
15
echo $UPLOAD
16
n=0
17
# get chunck files infos
18
for f in chunk*; do
19
  fname[$n]=$f
20
  fsize[$n]=$(ls -l $f | cut -d ' ' -f5)
21
  if [ $n -eq 0 ]; then
22
    bindex[$n]=0
23
  else
24
    bindex[$n]=$((${eindex[$(($n-1))]} + 1))
25
  fi
26
  eindex[$n]=$((fsize[$n] + ${bindex[$n]} - 1))
27
  n=$(($n+1))
28
done
29

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

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

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