-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·119 lines (98 loc) · 2.65 KB
/
setup.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
#!/bin/bash
# default setting
EXTADDR=""
DOCKER=false
IMAGE_VERSION=latest
RESET=false
usage() {
echo "syntax: $0 [options] <data_root> <moniker> [peers] "
echo "options:"
echo " -d use docker with specified image version"
echo " -r reset data root"
echo " -e external address"
echo " -h print usage"
}
while getopts "d:re:h" arg; do
case $arg in
d)
DOCKER=true
IMAGE_VERSION=$OPTARG
;;
r)
RESET=true
;;
e)
EXTADDR=$OPTARG
;;
h | *)
usage
exit
;;
esac
done
shift $(( OPTIND - 1 ))
DATAROOT=$1
MONIKER=$2
PEERS=$3
OS=$(uname)
if [ -z "$DATAROOT" -o -z "$MONIKER" ]; then
usage
exit
fi
echo "data root = $DATAROOT"
echo "moniker = $MONIKER"
echo "peers = $PEERS"
echo "docker = $DOCKER"
echo "reset = $RESET"
echo "extaddr = $EXTADDR"
# reset DATAROOT
if [ "$RESET" = true ]; then
rm -rf $DATAROOT
fi
# make sure dir struct
mkdir -p $DATAROOT/amo/config
mkdir -p $DATAROOT/amo/data
# build config.toml
cp -f config.toml.in config.toml
sed -e s/@moniker@/$MONIKER/ -i.tmp config.toml
sed -e s/@peers@/$PEERS/ -i.tmp config.toml
if [ ! -z "$EXTADDR" ]; then
sed -e s/@external@/tcp:\\/\\/$EXTADDR:26656/ -i.tmp config.toml
else
sed -e s/@external@// -i.tmp config.toml
fi
# put config.toml into DATAROOT
mv -f config.toml $DATAROOT/amo/config/
# put genesis.json if exists
if [ -f genesis.json ]; then
cp -f genesis.json $DATAROOT/amo/config/
fi
# put node_key.json, priv_validator_key.json, priv_validator_state.json into DATAROOT
if [ -f node_key.json ]; then
cp -f node_key.json $DATAROOT/amo/config/
fi
if [ -f priv_validator_key.json ]; then
cp -f priv_validator_key.json $DATAROOT/amo/config/
fi
if [ ! -f $DATAROOT/amo/data/priv_validator_state.json ]; then
cp priv_validator_state.json $DATAROOT/amo/data/
fi
if [ "$DOCKER" = true ]; then
# init tendermint
docker run -it --rm -v $DATAROOT/amo:/amo amolabs/amod:$IMAGE_VERSION amod tendermint init
# show tendermint id
docker run -it --rm -v $DATAROOT/amo:/amo amolabs/amod:$IMAGE_VERSION amod tendermint show_node_id 2> /dev/null
else
# prepare amod.service
cp run.sh /root/amod_run.sh
cp -f amod.service.in amod.service
sed -e s#@dataroot@#$DATAROOT/amo# -i.tmp amod.service
cp amod.service /etc/systemd/system/amod.service
# enable amod.service
systemctl enable amod
# init tendermint
amod --home $DATAROOT/amo tendermint init
# show tendermint node id
amod --home $DATAROOT/amo tendermint show_node_id 2> /dev/null
fi
rm -f *.tmp