-
Notifications
You must be signed in to change notification settings - Fork 20
/
compile
executable file
·310 lines (232 loc) · 6.76 KB
/
compile
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
#!/bin/bash
function post_compile {
cp ./lib/saito/boot.js ./web/saito/saito2.js
cat ./web/saito/saito.js >> ./web/saito/saito2.js
mv -f ./web/saito/saito2.js ./web/saito/saito.js
}
function reset_bundler {
echo "Resetting Saito to Default Modules!"
echo ""
rm -rf ./bundler
if [ ! -d "./bundler" ]; then
mkdir -p bundler/default/mods
mkdir -p data/blocks
cp -rf ./lib bundler/default/lib
cp -rf ./config bundler/default/config
cp -rf ./apps bundler/default/apps
copy_lite_mods_to_bundler_directory
echo ""
echo "Compiling Lite-Client JS..."
rm -rf bundler/default/mods/appstore/bundler/dist
for md in bundler/default/mods/* ; do
rm -rf "$md/web"
rm -rf "$md/sql"
rm -rf "$md/www"
rm -rf "$md/docs"
rm -rf "$md/DESCRIPTION.txt"
rm -rf "$md/BUGS.txt"
rm -rf "$md/README.txt"
rm -rf "$md/*.md"
rm -rf "$md/README.md"
rm -rf "$md/install.sh"
rm -rf "$md/license"
done
fi
}
function reset_nonpersistent {
mkdir -p data/blocks
# ensure deleted
rm -f ./web/saito/saito.js
# we explicitly don't delete registry/balance databases
rm -f ./data/appstore.sq3
#rm -f ./data/covid19.sq3
#rm -f ./data/post.sq3
rm -f ./data/hospital.sq3
rm -f ./data/records.sq3
rm -f ./data/archive.sq3
rm -f ./data/explorer.sq3
rm -f ./data/timeclock.sq3
rm -f ./data/earlybirds.sq3
rm -f ./data/arcade.sq3
rm -f ./data/chat.sq3
rm -f ./data/database.sq3
rm -f ./data/bank.sq3
rm -f ./data/escrow.sq3
rm -f ./data/log.txt
rm -f ./data/*.sq3-journal
find ./data/blocks/ -name '*.blk' | xargs rm -r
rm -f ./data/shashmaps/*.smap
rm -f ./data/blocks/*.zip
rm -f ./data/blocks/*.segadd
rm -f ./data/tmp/*.blk
rm -f ./data/tmp/*.zip
rm -f ./config/options
rm -rf ./mods/appstore/mods
mkdir ./mods/appstore/mods
#
# do not delete compiled software
#
# rm -rf ./mods/appstore/bundler/dist/
rm -f ./mods/forum/web/img/thumbnails/*.png
rm -f ./mods/registry/web/addresses.txt
rm -f ./mods/appstore/mods/*
rm -rf ./mods/appstore/bundler/mods/*
rm -rf ./mods/appstore/bundler/dist/*
rm -f ./mods/appstore/bundler/*.js
rm -f ./mods/appstore/bundler/*.json
rm -f ./logs/*
#let the system know that users pre-existed a reset.
if [ -f ./data/rewards.sq3 ]; then
echo "update users set latest_tx = -1;" | sqlite3 ./data/rewards.sq3
fi
if [ ! -f ./config/modules.config.js ]; then
cp ./config/modules.default.js ./config/modules.config.js
fi
if [ -f config/options.conf ]; then
cp config/options.conf config/options
fi
}
function reset_persistent {
rm -f ./data/forum.sq3
rm -f ./data/post.sq3
rm -f ./data/registry.sq3
rm -f ./data/rewards.sq3
rm -f ./data/forum.sq3
rm -f ./data/tutorial.sq3
rm -f ./web/client.options
mkdir -p data/blocks
}
function copy_lite_mods_to_bundler_directory {
PMOD=0
declare -a ARRAY_OF_MODS
input="./config/modules.config.js"
while IFS= read -r line
do
if [[ $PMOD == 1 ]]; then
if ! [[ $line == *"//"* ]]; then
SUBSTRING=$(echo $line| cut -d"'" -f 2)
SUBSTRING2=$(echo $SUBSTRING| cut -d"/" -f 1)
if ! [[ $SUBSTRING2 == *"]"* ]]; then
if ! [[ $SUBSTRING2 == *"}"* ]]; then
ARRAY_OF_MODS+=($SUBSTRING2)
fi
fi
fi
fi
if [[ $line == *"lite"* ]]; then
PMOD=1
fi
done < $input
for i in "${ARRAY_OF_MODS[@]}"; do
echo "installing mod for lite-client bundling: $i";
cp -rf ./mods/$i bundler/default/mods/$i
done
rm -f ./bundler/default/mods/appstore/mods/*
rm -f ./bundler/default/mods/appstore/bundler/*
rm -f ./bundler/default/mods/appstore/dist/*
}
echo "$1"
echo "$2"
echo "$3"
if [ "$1" == "init" ]; then
if [ -f config/modules.config.js ]; then
echo "";
echo "It looks like you have already installed Saito. If you are "
echo "trying to change the modules that are installed on your "
echo "machine you can edit the file: "
echo "";
echo " config/modules.config.js";
echo "";
echo "And run the following command: ";
echo "";
echo " > npm run compile";
echo "";
echo "Continuing with this installation will delete existing data,"
echo "reset your wallet and resync the blockchain. Are you sure "
echo "you wish to continue? (yes/no)"
while true; do
read -p "> " yn
case $yn in
yes* ) cp config/modules.default.js config/modules.config.js; break;;
no* ) exit;;
* ) echo 'Please answer "yes" or "no".';;
esac
done
elif [ -f config/modules.default.js ]; then
echo "";
echo "Installing and compiling Saito with default modules..."
echo "";
fi
if [ -f config/saito.io.conf ]; then
while true; do
echo ""
echo "You can join the Saito Network and participate in development"
echo "of the public chain. Or you can setup a local node for the"
echo "easier development and testing of applications."
echo "";
echo "Join saito.io (saito) or local install (local): ";
read -p "> " yn
case $yn in
saito* ) cp config/saito.io.conf config/options; break;;
local* ) break;;
* ) echo 'Please answer "saito" or "local".';;
esac
done
fi
fi
if [ "$1" == "nuke" ] || [ "$1" == "init" ]; then
echo ""
echo ""
echo " _.-^^---....,,-- "
echo " _-- --_ "
echo " < >) "
echo " | | "
echo " \._ _./ "
echo " '''--. . , ; .--''' "
echo " | | | "
echo " .-=|| | |=-. "
echo " -=#$%&%$#=-' "
echo " | ; :| "
echo " .,-#%&$@%#&#~, "
echo " ------------------------- "
echo " NUKING YOUR SAITO INSTALL "
echo " ------------------------- "
echo " (resetting configuration) "
echo ""
echo ""
reset_nonpersistent
reset_persistent
reset_bundler
node webpack/webpack.prod.js $2 $3
post_compile
fi
if [ "$1" == "reset" ]; then
echo ""
echo ""
echo " -------------------------- "
echo " RESETTING ALL BUT CORE DATA "
echo " -------------------------- "
echo " (resetting blockchain) "
echo ""
echo ""
reset_nonpersistent
reset_bundler
node webpack/webpack.prod.js $2 $3
post_compile
fi
if [ "$1" == "recompile" ]; then
echo ""
echo " ------------------------- "
echo " RE-COMPILING JAVASCRIPT "
echo " ------------------------- "
echo " (resetting configuration) "
echo ""
echo ""
# making sure we have some modules defined.
if [ ! -f ./config/modules.config.js ]; then
cp ./config/modules.default.js ./config/modules.config.js
fi
reset_bundler
node webpack/webpack.prod.js $2 $3
post_compile
fi