forked from Anfauglith/core-control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccontrol.sh
executable file
·316 lines (212 loc) · 7.63 KB
/
ccontrol.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
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
314
315
316
#!/bin/bash
if [[ -z "$NETWORK" ]];then
echo "ERROR: Please run this script with NETWORK environment variable set to either mainnet or devnet."
exit 1;
fi
basedir="$(dirname "$(cat $HOME/.bashrc | grep ccontrol | awk -F"=" '{print $2}')")"
execdir="$(dirname "$0")"
if [[ "$basedir" != "." && "$execdir" != "." ]]; then
cd $basedir
elif [[ "$basedir" = "." && "$execdir" != "." ]]; then
cd $PWD/$execdir
fi
basedir="$PWD"
. "project.conf.$NETWORK"
. "project.conf.common"
. "functions.sh"
. "misc.sh"
main () {
if [[ ( "$1" = "install" ) && ( "$2" = "core" || -z "$2" ) && ( -z "$3" ) ]]; then
if [[ -d $data || -d $core ]]; then
echo -e "\n${red}Core already installed. Please remove first.${nc}\n"
exit 1
fi
sudo apt update > /dev/null 2>&1
sysinfo
install_deps &
echo -ne "${cyan}Installing Dependencies... ${red}"
while [ -d /proc/$! ]; do
printf "\b${sp:i++%${#sp}:1}" && sleep .1
done
echo -e "\b${green}Done${nc}"
secure &
echo -ne "${cyan}Securing System... ${red}"
while [ -d /proc/$! ]; do
printf "\b${sp:i++%${#sp}:1}" && sleep .1
done
echo -e "\b${green}Done${nc}"
install_db &
echo -ne "${cyan}Installing Database... ${red}"
while [ -d /proc/$! ]; do
printf "\b${sp:i++%${#sp}:1}" && sleep .1
done
echo -e "\b${green}Done${nc}"
install_core &
echo -ne "${cyan}Setting up Core... ${red}"
while [ -d /proc/$! ]; do
printf "\b${sp:i++%${#sp}:1}" && sleep .1
done
echo -e "\b${green}Done${nc}\n"
elif [[ ( "$1" = "update" ) && ( "$2" = "core" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
cd $core > /dev/null 2>&1
git_check_core
local hydra_plugin_installed="$(cat $config/plugins.js | grep '@internet-of-people/hydra-plugin')"
if [ ! -f "$config/app.js" ]; then
cp $core/packages/core/bin/config/$network/app.js $config/app.js
fi
local hydra_appjs_installed="$(cat $config/app.js | grep '@internet-of-people/hydra-plugin')"
if [ "$up2date" = "yes" ] && [ ! -z "$hydra_plugin_installed" ] && [ ! -z "$hydra_appjs_installed" ]; then
echo -e "Already up-to-date."
exit 1
fi
git checkout . 2>&1
git fetch 2>&1
git reset --hard origin/$branch 2>&1
git checkout $branch 2>&1
if [ "$?" != "0" ]; then
rm yarn.lock > /dev/null 2>&1
fi
if [ "$?" != "0" ]; then
echo -e "\n${red}git pull failed - check for conflicts${nc}\n"
exit 1
fi
sysinfo
update &
echo -ne "${cyan}Updating Core... ${red}"
while [ -d /proc/$! ]; do
printf "\b${sp:i++%${#sp}:1}" && sleep .1
done
echo -e "\b${green}Done${nc}\n"
elif [[ ( "$1" = "remove" ) && ( "$2" = "core" || -z "$2" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data && ! -d $core ]]; then
echo -e "\n${red}Core not installed.${nc}\n"
exit 1
fi
sudo apt update > /dev/null 2>&1
sysinfo
remove &
echo -ne "${cyan}Removing Core... ${red}"
while [ -d /proc/$! ]; do
printf "\b${sp:i++%${#sp}:1}" && sleep .1
done
echo -e "\b${green}Done${nc}\n"
elif [[ ( "$1" = "config" ) && ( "$2" = "reset" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
config_reset &
sleep 1
echo -e "\n${cyan}Processes Stopped...${nc}"
sleep 1
echo -e "${cyan}Configs Replaced with Defaults...${nc}"
echo -e "${green}All Done!${nc}\n"
elif [[ ( "$1" = "start" ) && ( "$2" = "relay" || "$2" = "forger" || "$2" = "all" || -z "$2" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
if [ -z "$2" ]; then
set -- "$1" "all"
fi
start $2
echo -e "\n${green}All Done!${nc}\n"
elif [[ ( "$1" = "restart" ) && ( "$2" = "relay" || "$2" = "forger" || "$2" = "all" || "$2" = "safe" || -z "$2" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
if [ -z "$2" ]; then
set -- "$1" "all"
fi
restart $2
echo -e "\n${green}All Done!${nc}\n"
elif [[ ( "$1" = "stop" ) && ( "$2" = "relay" || "$2" = "forger" || "$2" = "all" || -z "$2" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
if [ -z "$2" ]; then
set -- "$1" "all"
fi
stop $2
echo -e "\n${green}All Done!${nc}\n"
elif [[ ( "$1" = "status" ) && ( "$2" = "relay" || "$2" = "forger" || "$2" = "all" || -z "$2" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
if [ -z "$2" ]; then
set -- "$1" "all"
fi
status $2
elif [[ ( "$1" = "system" ) && ( "$2" = "info" || -z "$2" ) && ( -z "$3" ) ]]; then
sysinfo
elif [[ ( "$1" = "system" ) && ( "$2" = "update" ) && ( -z "$3" ) ]]; then
sysinfo
sudo apt update > /dev/null 2>&1
sysupdate
elif [[ ( "$1" = "logs" ) && ( "$2" = "relay" || "$2" = "forger" || "$2" = "all" || -z "$2" ) && ( -z "$3" ) ]]; then
if [ -z "$2" ]; then
set -- "$1" "all"
fi
logs $2
elif [[ ( "$1" = "secret" ) && ( ( "$2" = "set" && ! -z "${14}" && -z "${15}" ) || ( "$2" = "clear" && -z "$3" ) ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
secret $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14}
echo -e "\n${green}All Done!${nc}\n"
elif [[ ( "$1" = "snapshot" ) && ( "$2" = "create" || "$2" = "restore" ) && ( -z "$3" ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
fi
if [[ "$2" = "restore" && ! -d "$HOME/.local/share/$name-core/$network/snapshots" ]]; then
echo -e "\n${red}No Snapshot Found!${nc}\n"
exit 1
elif [[ "$2" = "restore" && -z "$(ls $HOME/.local/share/$name-core/$network/snapshots)" ]]; then
echo -e "\n${red}No Snapshot Found!${nc}\n"
exit 1
fi
snapshot $2
elif [[ ( "$1" = "update" ) && ( "$2" = "self" ) && ( -z "$3" ) ]]; then
git fetch
git reset --hard origin/$branch
elif [[ ( "$1" = "remove" ) && ( "$2" = "self" ) && ( -z "$3" ) ]]; then
selfremove
echo -e "\n${green}All Done!${nc}\n"
elif [[ ( "$1" = "update" ) && ( "$2" = "check" || -z "$2" ) && ( -z "$3" ) ]]; then
update_info
elif [[ ( "$1" = "rollback" ) && ( ! -z "$2" ) && ( -z "$3" ) ]]; then
rollback $2
elif [[ ( "$1" = "database" ) && ( "$2" = "clear" ) && ( -z "$3" ) ]]; then
db_clear
echo -e "\n${green}All Done!${nc}\n"
elif [[ ( "$1" = "plugin" ) && ( ( ( "$2" = "add" || "$2" = "remove" || "$2" = "update" ) && ! -z "$3" && -z "$4" ) || ( ( "$2" = "list" || -z "$2" ) && -z "$3" ) ) ]]; then
if [[ ! -d $data || ! -d $core ]]; then
echo -e "\n${red}Core not installed. Please install first.${nc}\n"
exit 1
elif [[ ! -d plugins || -z "$(ls plugins)" ]]; then
echo -e "\n${red}No plugins found.${nc}\n"
exit 1
fi
if [ -z "$2" ]; then
set -- "$2" "list"
fi
if [ "$2" = "list" ]; then
plugin_list
else
plugin_manage $2 $3
fi
else
wrong_arguments
fi
trap cleanup SIGINT SIGTERM SIGKILL
}
main "$@"