forked from Qwinn1/forktools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forkupdateq
313 lines (276 loc) · 13.7 KB
/
forkupdateq
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#! /usr/bin/env bash
function print_usage () {
echo "forkupdate help:"
echo
echo "SYNOPSIS: Updates a fork to the most recent tagged release with a single command."
echo " Removes the existing blockchain directory and recreates it with git clone as a"
echo " fresh installation. forkupdate can accept a -b switch. Whether you use -b or not,"
echo " forkupdate will grab the same version that git clone would with the same setting (or"
echo " lack thereof)."
echo " If the git clone fails, or if the user does not confirm acceptance at the end"
echo " of the process, the user's original -blockchain directory and config.yaml are restored."
echo " Note that forkupdate will backup and then remove the existing config.yaml so that"
echo " 'fork init' during the update process will recreate a fresh config.yaml that includes any"
echo " new parameters added by the development team. Target addresses, farmer peer and any"
echo " multiprocessing_limit will be transferred to the new config.yaml, and other settings"
echo " will be configured via forkfixconfig (so your settings in ftconfigs/config.forkfixconfig"
echo " will be applied)."
echo
echo "PARAMETERS:"
echo " forkname Required."
echo " -b OPTIONAL. Update to a specific branch/tag, same usage as -b in git clone."
echo " -help | --help Show this information again."
echo
exit 0
}
REALPWD=$PWD
VALIDATEFORKNAME='Yes'
. ftinit.sh
FORKNAME=$1
CURRENTCONFIG=$FORKTOOLSHIDDENDIRS/.$FORKNAME/mainnet/config/config.yaml
CONFIGFOUND=$(ls -lt $CURRENTCONFIG | wc -l )
if [[ $CONFIGFOUND = 0 ]]; then
echo "Existing config.yaml file not found. Aborting forkupdate."
exit
fi
if [[ $2 != '' && $2 != '-b' ]]; then
echo "Incorrect parameters. Second parameter can only be -b, and must be followed by a valid github tag/branch."
print_usage
exit
fi
# CD and activate venv
cd $FORKTOOLSBLOCKCHAINDIRS/$FORKNAME-blockchain
. ./activate
# Get repository using git remote -v
GITREPO=$(git remote -v | grep "fetch" | awk '{print $2}' )
BLOCKDIR=$(echo $GITREPO | sed 's/.*\///g' | sed 's/\.git//' )
if [[ ! -d $FORKTOOLSBLOCKCHAINDIRS/$BLOCKDIR ]]; then
echo "forkupdate: The directory $FORKTOOLSBLOCKCHAINDIRS/$BLOCKDIR does not seem to currently exist. Aborting forkupdate."
exit
fi
INDIRECTORY=$(echo $REALPWD | grep "$BLOCKDIR" )
if [[ $INDIRECTORY != '' ]]; then
echo "forkupdate will destroy and recreate the $FORKTOOLSBLOCKCHAINDIRS/$BLOCKDIR directory, and you appear to currently be inside that directory."
echo "This could lead to errors after forkupdate completes."
echo "Please navigate to a directory safely outside of the $BLOCKDIR directory and then restart forkupdate."
exit
fi
PROCESSEF=$( getproclist )
. $FORKTOOLSDIR/ftcheckprocs.sh
OLDVERSION=$(forkq $FORKNAME ver)
echo "forkupdate: Updating from current version # :" $OLDVERSION
POOLLISTSECTION=0
SETPOOLLIST=''
# Get farmer peer from harvester section. Uses c1grep function instead of grep so as to not trigger ERROR trap code 1 (no line found) which is intended
OLDIFS=$IFS
IFS=''
while read line; do
WORKLINE=$(sed 's/#.*//' <<< "$line" ) # This removes any comments from consideration for alteration
TESTSECTION=$(c1grep -e '^harvester:' -e '^pool:' -e '^farmer:' -e '^full_node:' -e '^timelord:' -e '^timelord_launcher:' -e '^ui:' -e '^introducer:' -e '^wallet:' -e '^logging:' -e '^seeder:' <<< "$WORKLINE" )
if [[ $TESTSECTION != '' && $TESTSECTION != $SECTION ]]; then
SECTION=$TESTSECTION
fi
if [[ $SECTION == *harvester:* && $WORKLINE == *host:* ]]; then
FARMERPEER=$(grep "host: " <<< "$WORKLINE" | sed 's/host: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
fi
if [[ $SECTION == *farmer:* && $WORKLINE == *target_address:* ]]; then
SETFARMTARGET=$(grep "target_address: " <<< "$WORKLINE" | sed 's/.*target_address: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
fi
if [[ $SECTION == *pool:* && $WORKLINE == *target_address:* ]]; then
SETPOOLTARGET=$(grep "target_address: " <<< "$WORKLINE" | sed 's/.*target_address: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
fi
# Foxypool support
if [[ $SECTION == *farmer:* && $WORKLINE == *pool_url:* ]]; then
SETFOXYPOOLURL=$( echo $line )
fi
if [[ $SECTION == *farmer:* && $WORKLINE == *pool_payout_address:* ]]; then
SETFOXYPOOLPAYOUTADDRESS=$( echo $line )
fi
# Regular chia pooling support
if [[ $SECTION == *pool:* && $WORKLINE == *pool_list:* ]]; then
SETPOOLLIST=$( echo $line )
POOLLISTSECTION=1
continue
fi
if [[ $SECTION == *pool:* && $WORKLINE == *selected_network:* ]]; then
POOLLISTSECTION=0
fi
if [[ $SECTION == *pool:* && $POOLLISTSECTION == 1 ]]; then
SETPOOLLIST+=$( printf '\n%s' $line )
fi
if [[ $SECTION == *full_node:* && $WORKLINE == *database_path:* && $WORKLINE != *simulator_database_path:* ]]; then
ORIGMAINDBPATH=$(grep " database_path: " <<< "$WORKLINE" | sed 's/.*database_path: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
fi
if [[ $SECTION == *wallet:* && $WORKLINE == *database_path* ]]; then
ORIGWALLETDBPATH=$(grep " database_path: " <<< "$WORKLINE" | sed 's/.*database_path: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
fi
done < $CURRENTCONFIG
IFS=$OLDIFS
ORIGMULTIPROC=$(grep "multiprocessing_limit" $CURRENTCONFIG )
echo
echo "During forkupdate, a fresh config.yaml will be generated by 'fork init' in order to add any new parameters."
echo "The following values are being read from the current config.yaml for transfer to the new config.yaml at the end of forkupdate."
echo " Farmer peer : " $FARMERPEER
echo " Farmer target address : " $SETFARMTARGET
echo " Pool target address : " $SETPOOLTARGET
echo " Multiprocessing_limit : " $ORIGMULTIPROC
echo " Main database path : " $ORIGMAINDBPATH
echo " Wallet database path : " $ORIGWALLETDBPATH
if [[ $SETPOOLLIST != '' ]]; then
echo "Standard chia pooling parameters detected. Preserving pool_list parameters:"
OLDIFS=$IFS
IFS=''
echo $SETPOOLLIST
IFS=$OLDIFS
fi
if [[ $SETFOXYPOOLURL != '' && $SETFOXYPOOLPAYOUTADDRESS != '' ]]; then
echo "Foxypool pooling parameters detected. Preserving foxypool parameters:"
OLDIFS=$IFS
IFS=''
echo $SETFOXYPOOLURL
echo $SETFOXYPOOLPAYOUTADDRESS
IFS=$OLDIFS
fi
echo
echo "Checking if any forkpatch patches were applied so they can be re-applied at the end of forkupdate."
MULTIPROCPATCH=$FORKTOOLSBLOCKCHAINDIRS/$FORKNAME-blockchain/$FORKNAME/consensus/blockchain.py
MULTIPROCPATCH=$( c1grep -c 'added by forkpatch -multiproc' $MULTIPROCPATCH )
if [[ $MULTIPROCPATCH > 0 ]]; then
echo " Confirmed forkpatch -multiproc is applied. Will attempt to reapply -multiproc patch before forkupdate ends."
fi
LOGWINNINGPLOTSPATCH=$FORKTOOLSBLOCKCHAINDIRS/$FORKNAME-blockchain/$FORKNAME/harvester/harvester_api.py
LOGWINNINGPLOTSPATCH=$( c1grep -c 'added by forkpatch -logwinningplots' $LOGWINNINGPLOTSPATCH )
if [[ $LOGWINNINGPLOTSPATCH > 0 ]]; then
echo " Confirmed forkpatch -logwinningplots is applied. Will attempt to reapply -logwinningplots patch before update ends."
fi
echo
echo "forkupdate: Stopping services."
forkstop $1
deactivate
DATESUFFIX=$(date +%F)
echo "forkupdate: Renaming existing config.yaml to config.yaml.preupdate-$DATESUFFIX"
mv $CURRENTCONFIG $CURRENTCONFIG.preupdate-$DATESUFFIX
cd $FORKTOOLSBLOCKCHAINDIRS
echo "forkupdate: Moving existing $BLOCKDIR directory to $BLOCKDIR.preupdate-$DATESUFFIX"
mv $BLOCKDIR $BLOCKDIR.preupdate-$DATESUFFIX
git clone $GITREPO $2 $3
if [[ ! -d $FORKTOOLSBLOCKCHAINDIRS/$FORKNAME-blockchain ]]; then
echo "forkupdate: git clone statement failed. Restoring original $BLOCKDIR directory and config.yaml and aborting."
mv $CURRENTCONFIG.preupdate-$DATESUFFIX $CURRENTCONFIG
mv $BLOCKDIR.preupdate-$DATESUFFIX $BLOCKDIR
exit
fi
cd $FORKTOOLSBLOCKCHAINDIRS/$FORKNAME-blockchain
echo "forkupdate: Running 'sh install.sh'. Any request for sudo password comes from that script, not forkupdate."
sh install.sh
. ./activate
$1 init
$1 init --fix-ssl-permissions
echo "forkupdate: Running 'forkaddplotdirs $FORKNAME'"
forkaddplotdirsq $FORKNAME
echo "forkupdate: Running 'forkfixconfig $FORKNAME $FARMERPEER'"
forkfixconfigq $FORKNAME $FARMERPEER
OLDIFS=$IFS
IFS=''
LINENUMBER=0
while read line; do
((LINENUMBER=$LINENUMBER+1))
WORKLINE=$(sed 's/#.*//' <<< "$line" ) # This removes any comments from consideration for alteration
TESTSECTION=$(c1grep -e '^harvester:' -e '^pool:' -e '^farmer:' -e '^full_node:' -e '^timelord:' -e '^timelord_launcher:' -e '^ui:' -e '^introducer:' -e '^wallet:' -e '^logging:' -e '^seeder:' <<< "$WORKLINE" )
if [[ $TESTSECTION != '' && $TESTSECTION != $SECTION ]]; then
SECTION=$TESTSECTION
fi
if [[ $SECTION == *farmer:* && $WORKLINE == *target_address:* ]]; then
OLDFARMTARGET=$(grep "target_address: " <<< "$WORKLINE" | sed 's/.*target_address: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
OLDFARMTARGETLINENO=$LINENUMBER
fi
if [[ $SECTION == *pool:* && $WORKLINE == *target_address:* ]]; then
OLDPOOLTARGET=$(grep "target_address: " <<< "$WORKLINE" | sed 's/.*target_address: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
OLDPOOLTARGETLINENO=$LINENUMBER
fi
if [[ $SECTION == *pool:* && $WORKLINE == *network_overrides:* ]]; then
NETWORKOVERRIDESLINENO=$LINENUMBER
fi
if [[ $SECTION == *farmer:* && $WORKLINE == *pool_public_keys:* ]]; then
POOLPUBLICKEYSLINENO=$LINENUMBER
fi
if [[ $SECTION == *farmer:* && $WORKLINE == *pool_share_threshold:* ]]; then
POOLSHARETHRESHOLDLINENO=$LINENUMBER
fi
if [[ $SECTION == *full_node:* && $WORKLINE == *database_path:* && $WORKLINE != *simulator_database_path:* ]]; then
NEWMAINDBPATH=$(grep " database_path: " <<< "$WORKLINE" | sed 's/.*database_path: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
NEWMAINDBLINENO=$LINENUMBER
fi
if [[ $SECTION == *wallet:* && $WORKLINE == *database_path:* && $WORKLINE != *simulator_database_path:* ]]; then
NEWWALLETDBPATH=$(grep " database_path: " <<< "$WORKLINE" | sed 's/.*database_path: //' | sed 's/"//g' | sed 's/'\''//g' | awk '{$1=$1};1')
NEWWALLETDBLINENO=$LINENUMBER
fi
done < "$CURRENTCONFIG"
IFS=$OLDIFS
if [[ $OLDFARMTARGET != '' && $OLDPOOLTARGET != '' ]]; then
echo "forkupdate: Setting farmer and pool reward target addresses in new config.yaml to pre-forkupdate values."
sed -i.bak "${OLDFARMTARGETLINENO}s/$OLDFARMTARGET/$SETFARMTARGET/" $CURRENTCONFIG
sed -i.bak "${OLDPOOLTARGETLINENO}s/$OLDPOOLTARGET/$SETPOOLTARGET/" $CURRENTCONFIG
# Making sure we don't add multiproc a second time in case forkfixconfig miraculously did it
else
echo "forkupdate: Original config did not have settings for both target addresses, so no address transfer is attempted."
echo " This is normal when this is just a harvester. If this is a farmer, make sure to edit your addresses."
fi
echo "forkupdate: Setting main and wallet database paths to pre-forkupdate values."
sed -i.bak "${NEWMAINDBLINENO}s|${NEWMAINDBPATH}|${ORIGMAINDBPATH}|" $CURRENTCONFIG
sed -i.bak "${NEWWALLETDBLINENO}s|${NEWWALLETDBPATH}|${ORIGWALLETDBPATH}|" $CURRENTCONFIG
# For the following inserts, make sure to work from the end of the file backwards. That way our inserts don't change line numbers captured above.
# Multiproc gets appended at the end, so do that first.
# Then standard chia pooling which is in the 'pool:' section
# Then foxypool settings which are in the 'farmer:' section.
NEWMULTIPROC=$( grep "multiprocessing_limit" $CURRENTCONFIG )
if [[ $NEWMULTIPROC == '' ]]; then
echo "forkupdate: Reapplying multiprocessing_limit."
echo >> "$CURRENTCONFIG"
echo $ORIGMULTIPROC >> "$CURRENTCONFIG"
fi
if [[ $SETPOOLLIST != '' ]]; then
echo "forkupdate: Reapplying standard chia pool settings."
sed -i.bak "${NETWORKOVERRIDESLINENO}r /dev/stdin" $CURRENTCONFIG <<< "$SETPOOLLIST"
fi
if [[ $SETFOXYPOOLURL != '' && $SETFOXYPOOLPAYOUTADDRESS != '' ]]; then
let FOXYPOOLPAYOUTADDRESSINSERTLINENO=( $POOLPUBLICKEYSLINENO - 1)
sed -i.bak "${FOXYPOOLPAYOUTADDRESSINSERTLINENO}r /dev/stdin" $CURRENTCONFIG <<< "$SETFOXYPOOLPAYOUTADDRESS"
let FOXYPOOLURLINSERTLINENO=( $POOLSHARETHRESHOLDLINENO + 1)
sed -i.bak "${FOXYPOOLURLINSERTLINENO}r /dev/stdin" $CURRENTCONFIG <<< "$SETFOXYPOOLURL"
fi
NEWVERSION=$(forkq $FORKNAME ver)
deactivate
echo
echo "Updated to $FORKNAME version # :" $NEWVERSION
echo "If there were no significant errors and you'd like to keep the results of this update, confirm acceptance with (Y/y)"
read -p "Press any other key to revert back to your previous version and config." -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "forkupdate: User has confirmed acceptance of results."
echo "forkupdate: Recreating any needed symlinks."
. $FORKTOOLSDIR/ftsymlinks.sh
echo "forkupdate: Removing backup $BLOCKDIR.preupdate-$DATESUFFIX"
cd $FORKTOOLSBLOCKCHAINDIRS
rm -rf $BLOCKDIR.preupdate-$DATESUFFIX/.git
rm -r $BLOCKDIR.preupdate-$DATESUFFIX
echo "forkupdate to $FORKNAME version # :" $NEWVERSION "completed successfully."
else
echo "forkupdate: User has not accepted results. Restoring pre-update -blockchain directory and config.yaml"
cd $FORKTOOLSBLOCKCHAINDIRS
rm -rf $BLOCKDIR/.git
rm -r $BLOCKDIR
mv $BLOCKDIR.preupdate-$DATESUFFIX $BLOCKDIR
mv $CURRENTCONFIG.preupdate-$DATESUFFIX $CURRENTCONFIG
fi
if [[ $MULTIPROCPATCH > 0 ]]; then
echo "Running 'forkpatch $FORKNAME -multiproc'"
forkpatchq $FORKNAME -multiproc
fi
if [[ $LOGWINNINGPLOTSPATCH > 0 ]]; then
echo "Running 'forkpatch $FORKNAME -logwinningplots'"
forkpatchq $FORKNAME -logwinningplots
fi
echo
. $FORKTOOLSDIR/ftrestart.sh
echo 'forkupdate: Complete'