-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset.sh
119 lines (96 loc) · 3.75 KB
/
reset.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
#!/bin/zsh
local local_path=$PWD
local script_src=${local_path}/scripts/cat-config
local node_network=$1
local node_type=$2
local catapult_server_src=$3
local network_private_key=$4
local network_public_key=$5
local template_name=$6
if [[ -z "${node_network}" ]] then;
echo "script must be called with one of the three options: --local | --existing | --foundation"
return 0
elif [[ -z "${node_type}" ]] then;
echo "script must be called with one of the three node types: api | peer | dual"
return 0
fi
echo "Welcome to the Catapult Config Utility"
# reapply data directory
echo "+ preparing fresh data directory"
rm -rf ${local_path}/data
mkdir ${local_path}/data
# reapply seed directory
echo "+ preparing fresh seed directory"
rm -rf ${local_path}/seed
mkdir ${local_path}/seed
# clear state directories
rm -rf state
rm -rf statedb
echo "<<< DONE"
# reset mongo
if [[ "peer" != "${node_type}" ]] then;
echo
echo "+ resetting mongo"
pushd .
source ${script_src}/reset_mongo.sh ${catapult_server_src}
popd
echo "<<< DONE"
echo
fi
# clear logs
echo "+ clearing logs"
touch catapult_server.reset.log # suppress glob errors by creating a file that always matches the glob
rm -f *.log
rm -rf logs
# recreate resources
echo "+ recreating resources"
rm -rf ${local_path}/resources
mkdir ${local_path}/resources
function setup_existing() {
local node_type=$1
local template_name=$2
local catapult_server_src=$3
local boot_key=$4
local network_public_key=$5
local generation_hash=$(grep "private key:" ${script_src}/templates/${template_name}/generation_hash.txt | sed -e 's/private key://g' | tr -d ' ')
source ${script_src}/prepare_resources.sh ${node_type} ${catapult_server_src} ${script_src}/templates/${template_name} ${local_path}/resources ${boot_key} ${network_public_key} ${generation_hash}
cp -R ${script_src}/templates/${template_name}/seed/* ${local_path}/data
}
function setup_local() {
local node_type=$1
local catapult_server_src=$2
local boot_key=$3
local network_public_key=$4
echo "Generating network generation hash (UUID)"
source ${script_src}/generate_hash.sh ${catapult_server_src}
local generation_hash=$(grep "private key:" ${local_path}/generation_hash.txt | sed -e 's/private key://g' | tr -d ' ')
echo "Preparing resources"
source ${script_src}/prepare_resources.sh ${node_type} ${catapult_server_src} ${script_src}/templates/local ${local_path}/resources ${boot_key} ${network_public_key} ${generation_hash}
echo "Generating new nemesis block"
source ${script_src}/prepare_nemesis_block.sh ${catapult_server_src} ${boot_key} ${generation_hash}
}
function setup_foundation() {
cp scripts/templates/foundation/foundation.peers.p2p.json resources/peers-p2p.json
cp scripts/templates/foundation/foundation.peers.api.json resources/peers-api.json
}
case "${node_network}" in
## Prepares a standalone, single local node with its own completely new network
--local)
local boot_key=${network_private_key}
local public_key=${network_public_key}
setup_local ${node_type} ${catapult_server_src} ${boot_key} ${public_key}
;;
## Prepares a node that is capable of connecting to the Foundation network
--foundation)
## Copy nemesis seed
## Copy resource files (provide root dir instead of catapult-server)
## Ready to start with start.sh
setup_foundation
;;
## Prepare a node that is ready to connect to an existing network
--existing)
local boot_key=${network_private_key}
local network_public_key=${network_public_key}
setup_existing ${node_type} ${template_name} ${catapult_server_src} ${boot_key} ${network_public_key}
;;
esac