-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbxjoin.sh
executable file
·118 lines (95 loc) · 2.86 KB
/
sbxjoin.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
shopt -s extglob
if (( $# < 2 )); then
echo "Usage : in_prefix out_file"
exit 1
fi
in_prefix=$1
out_file=$2
sbx_version=17
sbx_block_size=512
out_container=$in_prefix.$out_file.tmp
rm -rf $out_container
echo "Decoding parts"
for file in $in_prefix.part*; do
if [[ $file == *.sbx ]]; then
echo " Decoding $file"
output=$(rsbx sort --json $file $file.sorted --burst 0)
error=$(echo $output | jq -r ".error")
if [[ $error != null ]]; then
echo " Error occured during sorting"
echo " $error"
exit 1
fi
output=$(rsbx repair --json $file.sorted)
error=$(echo $output | jq -r ".error")
if [[ $error != null ]]; then
echo " Error occured during repairing"
echo " $error"
exit 1
fi
output=$(rsbx decode --json $file.sorted)
if [[ $error != "null" ]]; then
echo " Error occured during encoding"
echo " $error"
exit 1
fi
recorded_hash=$(echo $output | jq -r ".stats.recordedHash")
output_hash=$(echo $output | jq -r ".stats.hashOfOutputFile")
if [[ $recorded_hash != $output_hash ]]; then
echo " Error : hash mismatch for $file"
exit 1
fi
rm $file.sorted
fi
done
echo "Concatenating parts"
for file in $in_prefix.part+([0-9]); do
echo " Adding $file to final container"
cat $file >> $out_container
if [ -f $file.sbx ]; then
rm $file
fi
done
echo "Sorting container"
output=$(rsbx sort --json $out_container $out_container.sorted --burst 0)
error=$(echo $output | jq -r ".error")
if [[ $error != null ]]; then
echo " Error occured during sorting"
echo " $error"
exit 1
fi
mv $out_container.sorted $out_container
echo "Repairing container"
output=$(rsbx repair --json $out_container)
error=$(echo $output | jq -r ".error")
if [[ $error != null ]]; then
echo " Error occured during repairing"
echo " $error"
exit 1
fi
repairs_failed=$(echo $output | jq -r ".stats.numberOfBlocksFailedToRepairData")
if (( $repairs_failed > 0 )); then
echo " Failed to repair container"
echo " The decoded data will have missing data"
fi
echo "Decoding container"
output=$(rsbx decode --json $out_container $out_file)
error=$(echo $output | jq -r ".error")
if [[ $error != null ]]; then
echo " Error occured during decoding"
echo " $error"
exit 1
fi
recorded_hash=$(echo $output | jq -r ".stats.recordedHash")
output_hash=$(echo $output | jq -r ".stats.hashOfOutputFile")
echo "Checking hash"
if [[ $recorded_hash != $output_hash ]]; then
echo " Error : Output file hash mismatch"
echo " Recorded hash : $recorded_hash"
echo " Output file hash : $output_hash"
exit 1
fi
# clean up
echo "Cleaning up"
rm -rf $out_container