-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspade-process-pending.sh
58 lines (58 loc) · 2.71 KB
/
spade-process-pending.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
if [[ -z "$1" || -z "$2" ]]; then
echo "Usage: $0 <MINER_ID> <Path to store cars>"
exit 1
fi
#check that path exists, remove trailing slash if present
if [ -d "$2" ]; then
echo "$2 is valid path"
downloadDirectory="${2%/}"
echo "using $downloadDirectory as download directory."
else
echo "$2 is not a valid path"
exit 1
fi
set -eu
set -o pipefail
miner=$1
pending_response=$(echo curl -sLH \"Authorization: $(./fil-spid.bash "$miner")\" https://api.spade.storage/sp/pending_proposals | sh)
# get response code from JSON output
pending_response_code=$(echo "$pending_response" | jq -r '.response_code')
pending_proposals=$(echo "$pending_response" | jq -r '.response.pending_proposals')
pending_count=$(echo "$pending_proposals" | grep -c "sample_import_cmd")
echo "$pending_response"
echo "API response code found: $pending_response_code"
echo "API pending proposals found: $pending_proposals"
echo "Pending Proposals count :$pending_count"
# if response code is 200
if [ "$pending_response_code" -eq 200 ]; then
for ((i = 0; i < "$pending_count"; i++)); do
#check_mpool
#check_jobs
echo "Processing entry: $i"
dl=$(echo "$pending_response" | jq -r --argjson idx "$i" '.response.pending_proposals[$idx].data_sources[0]')
deal_proposal_cid=$(echo "$pending_response" | jq -r --argjson idx "$i" '.response.pending_proposals[$idx].deal_proposal_cid')
piece_cid=$(echo "$pending_response" | jq -r --argjson idx "$i" '.response.pending_proposals[$idx].piece_cid')
f=$(basename -- "$dl")
echo "found Deal: $deal_proposal_cid"
echo "found Download URL: $dl"
echo "found Piece CID: $piece_cid"
echo "found carfile: $f"
if [ -e "$downloadDirectory/""$f".aria2 ]; then
echo "Parital File exist resume download it..."
aria2c -d "$downloadDirectory" "$dl" -j1 -x5 --auto-file-renaming=false
boostd import-data "$deal_proposal_cid" "$downloadDirectory/""$f"
# echo "boostd import-data "$deal_proposal_cid" "$downloadDirectory/""$f""
elif [ -e "$downloadDirectory/""$f" ]; then
echo "$f File already exists, assuming it has already been imported! copy and paste the next line if you need to import."
#echo "boostd import-data "$deal_proposal_cid" "$downloadDirectory/""$f""
else
echo "File does not exist download it..."
aria2c -d "$downloadDirectory" "$dl" -j1 -x5 --auto-file-renaming=false
boostd import-data "$deal_proposal_cid" "$downloadDirectory/""$f"
# echo "boostd import-data "$deal_proposal_cid" "$downloadDirectory/""$f""
fi
done
else
echo "Error: response code $pending_response_code"
fi