-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_client.sh
executable file
·173 lines (153 loc) · 6.78 KB
/
auto_client.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
file_path="/home/caslx/HIK/ceshi0411/NVR101/"
file_cache_path="/home/caslx/HIK/opsService/deal/cache/"
file_tar_path="/home/caslx/HIK/opsService/deal/tar/"
car_path="/home/caslx/HIK/opsService/deal/car/"
log_path="/home/caslx/HIK/opsService/deal/log"
file_name_path="$log_path/file_name"
import_log="$log_path/tmp/import.log"
commP_log="$log_path/tmp/commP.log"
deal_cid_log="$log_path/tmp/dealcid.log"
fail_log="$log_path/fail.log"
deal_log="$log_path/deal.log"
num=20
term=1468800
wallet="t1gaefbxfct24tfv4tck4lpbq3522sq7pb6odoiqq"
MinerAddress=t036295
echo -e "\n\n\n---------------------------------------------------------------------------------------"
echo -e "\033[33mNumber_files = $num\nClient_wallet = $wallet\nMinerAddress = $MinerAddress\033[0m"
echo -e "---------------------------------------------------------------------------------------\n"
while true
do
echo -n "Please confirm whether the configuration is correct (y/n):"
read -e result
if [[ $result == "y" ]];then
break
elif [[ $result == "n" ]];then
echo " n ,end of script!"
exit
else
echo "Incorrect input,please input again...."
fi
done
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Start running the script"
while true
do
tar_name=`date +%s`
while true
do
if [[ -s $deal_cid_log ]];then
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m One proposal was not accepted. Wait 60 seconds to recheck ..........."
sleep 60
else
break
fi
done
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Check the number of files in the directory directory=$file_path need=$num available=`ls $file_path|wc -l`"
if [ `ls $file_path|wc -l` -ge $num ];then
ls $file_path|head -$num >$file_name_path/$tar_name
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Move the files to be packaged to the specified directory info=$file_name_path/$tar_name"
for i in `ls $file_path|head -$num`;
do
mv $file_path$i $file_cache_path
done
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[31mERROR\033[0m Insufficient number of files in directory! Exit script need=$num available=`ls $file_path|wc -l`"
exit
fi
cd $file_cache_path
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Start packaging directories directory=$file_cache_path"
tar cfP $file_tar_path$tar_name.tar *
if [ $? = 0 ];then
:
rm -rf $file_cache_path*
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[31mERROR\033[0m Directory packaging failed, migrate all files! Exit script"
for i in `ls $file_cache_path`;
do
mv $file_cache_path$i $file_path
done
exit
fi
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Start converting file format file=$file_tar_path$tar_name.tar save=$car_path$tar_name.car"
lotus client generate-car $file_tar_path$tar_name.tar $car_path$tar_name.car
if [ $? = 0 ];then
:
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[31mERROR\033[0m Failed to convert file format! Exit script"
exit
fi
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Start importing files into lotus"
lotus client import --car $car_path$tar_name.car > $import_log
if [ $? = 0 ];then
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Import complete"
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m `cat $import_log|sed 's/Root/payload-CID:/'`"
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[31mERROR\033[0m Import failed! Exit script"
exit
fi
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Start commp calculation"
lotus client commP $car_path$tar_name.car > $commP_log
if [ $? = 0 ];then
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Commp calculation completed"
echo -ne `date +"%Y-%m-%d %H:%M:%S"`" \033[34mINFO\033[0m "$car_path$tar_name.car `cat $commP_log|sed 's/CID/Piece-CID/'`
echo
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[31mERROR\033[0m Commp calculation failed! Exit script"
exit
fi
PiecesCID=`cat $commP_log |awk 'NR==1 {print $2}'`
PayloadCID=`cat $import_log |awk '{print $NF}'`
now=`lotus status |awk 'NR==1 {print $3}'`
LatestTime=`expr $now + 20160`
Size=`awk 'NR==2 {print $3}' $commP_log`
Type=`awk 'NR==2 {print $NF}' $commP_log`
mm=`echo $Size|awk -F"." '{print $1}'`
for (( i=1;i<=10;i++ ))
do
let "n=2**$i"
if [ $mm -le $n ];then
PieceSize_=$n
break
fi
done
if [[ $Type == "GiB" ]];then
let "PieceSize=$PieceSize_*254*1024*1024*1024/256"
elif [[ $Type == "MiB" ]];then
let "PieceSize=$PieceSize_*254*1024*1024/256"
elif [[ $Type == "KiB" ]];then
let "PieceSize=$PieceSize_*254*1024/256"
else
echo "Type is err"
fi
SubmitFun(){
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Initiate transaction proposal"
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m lotus client deal --fast-retrieval=true --from=$wallet --manual-piece-cid=$PiecesCID --manual-piece-size=$PieceSize --manual-stateless-deal --verified-deal=false --start-epoch=$LatestTime $PayloadCID $MinerAddress 0 $term"
lotus client deal --fast-retrieval=true --from=$wallet --manual-piece-cid=$PiecesCID --manual-piece-size=$PieceSize --manual-stateless-deal --verified-deal=false --start-epoch=$LatestTime $PayloadCID $MinerAddress 0 $term > $deal_cid_log
if [ $? = 0 ];then
echo -ne `date +"%Y-%m-%d %H:%M:%S"` " \033[34mINFO\033[0m The proposal was successfully delivered!" proposal_CID=`cat $deal_cid_log`
echo
echo -ne "`date +"%Y-%m-%d %H:%M:%S"` Car_path:" $car_path$tar_name.car `cat $commP_log|sed 's/CID/Piece-CID/'|sed 's/Piece\ size/Piece-size/'` `cat $import_log|sed 's/Import/Import编号:/'|sed 's/Root/payload-CID:/'` "proposal_CID:" `cat $deal_cid_log` >> $deal_log
echo >> $deal_log
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[31mERROR\033[0m Proposal submission failed! Exit script"
echo -e "`date +"%Y-%m-%d %H:%M:%S"` Car_path: $car_path$tar_name.car info: `cat $deal_cid_log` command: lotus client deal --fast-retrieval=true --from=$wallet --manual-piece-cid=$PiecesCID --manual-piece-size=$PieceSize --manual-stateless-deal --verified-deal=false --start-epoch=$LatestTime $PayloadCID $MinerAddress 0 $term" >> $fail_log
exit
fi
}
SubmitFun
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Waiting for the proposal to be adopted ..........."
while true
do
if [[ -s $deal_cid_log ]];then
proposal_CID=`cat $deal_cid_log`
sleep 15
else
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO Congratulations! The proposal was accepted successfully! \033[0m"
rm -rf $car_path* $file_tar_path*
echo -e "`date +"%Y-%m-%d %H:%M:%S"` \033[34mINFO\033[0m Wait 5 seconds before submitting the next proposal ..........."
sleep 5
break
fi
done
done