-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·152 lines (128 loc) · 4.02 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·152 lines (128 loc) · 4.02 KB
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
#!/usr/bin/env bash
#
# Copyright (C) 2021-2023 diva.exchange
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Author/Maintainer: DIVA.EXCHANGE Association <contact@diva.exchange>
#
# -e Exit immediately if a simple command exits with a non-zero status
set -e
PROJECT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"/../
cd "${PROJECT_PATH}"
PROJECT_PATH=$( pwd )
# load helpers
source "${PROJECT_PATH}"/bin/util/echos.sh
source "${PROJECT_PATH}"/bin/util/helpers.sh
source "${PROJECT_PATH}"/bin/util/commands.sh
# env vars
I2P_LOGLEVEL=${I2P_LOGLEVEL:-none}
DIVA_TESTNET=${DIVA_TESTNET:-0}
IS_TESTNET=${IS_TESTNET:-0}
JOIN_NETWORK=${JOIN_NETWORK:-}
BASE_DOMAIN=${BASE_DOMAIN:-testnet.local}
SIZE_NETWORK=${SIZE_NETWORK:-7}
PURGE=${PURGE:-0}
BASE_IP=${BASE_IP:-172.19.72.}
PORT=${PORT:-17468}
NODE_ENV=${NODE_ENV:-production}
LOG_LEVEL=${LOG_LEVEL:-info}
# Handle joining
if [[ ${DIVA_TESTNET} -gt 0 ]]
then
JOIN_NETWORK=diva.i2p/testnet
SIZE_NETWORK=1
BASE_DOMAIN=testnet.diva.i2p
IS_TESTNET=1
fi
if [[ -n ${JOIN_NETWORK} ]]
then
SIZE_NETWORK=1
BASE_DOMAIN=join.${BASE_DOMAIN}
fi
if ! command_exists docker; then
error "docker not available. Please install it first.";
exit 1
fi
if ! command_exists docker compose; then
error "docker compose not available. Please install it first.";
exit 2
fi
PATH_DOMAIN=${PROJECT_PATH}/build/domains/${BASE_DOMAIN}
if [[ ! -d ${PATH_DOMAIN} ]]
then
mkdir "${PATH_DOMAIN}"
mkdir "${PATH_DOMAIN}"/genesis
mkdir "${PATH_DOMAIN}"/keys
mkdir "${PATH_DOMAIN}"/state
mkdir "${PATH_DOMAIN}"/blockstore
fi
cd "${PATH_DOMAIN}"
if [[ -f ./diva.yml ]]
then
as_root docker compose -f ./diva.yml down
fi
if [[ ${PURGE} -gt 0 ]]
then
warn "The confirmation of this action will lead to DATA LOSS!"
warn "If you want to keep the data, run a backup first."
confirm "Do you want to DELETE all local diva data and re-create your environment (y/N)?" || exit 3
if [[ -f ./diva.yml ]]
then
as_root docker compose -f ./diva.yml down --volumes
fi
as_root rm -rf "${PATH_DOMAIN}"/genesis/*
as_root rm -rf "${PATH_DOMAIN}"/keys/*
as_root rm -rf "${PATH_DOMAIN}"/state/*
as_root rm -rf "${PATH_DOMAIN}"/blockstore/*
fi
if [[ ! -f genesis/local.config ]]
then
running "Creating Genesis Block using I2P"
if [[ -f ./genesis-i2p.yml ]]
then
SIZE_NETWORK=${SIZE_NETWORK} as_root docker compose -f ./genesis-i2p.yml down --volumes
fi
cp "${PROJECT_PATH}"/build/genesis-i2p.yml ./genesis-i2p.yml
SIZE_NETWORK=${SIZE_NETWORK} as_root docker compose -f ./genesis-i2p.yml pull
SIZE_NETWORK=${SIZE_NETWORK} as_root docker compose -f ./genesis-i2p.yml up -d
running "Waiting for key generation"
# wait until all keys are created
while [[ ! -f genesis/local.config ]]
do
sleep 2
done
# shut down the genesis container and clean up
SIZE_NETWORK=${SIZE_NETWORK} as_root docker compose -f ./genesis-i2p.yml down --volumes
rm ./genesis-i2p.yml
# handle joining
if [[ -n ${JOIN_NETWORK} ]]
then
rm -rf ./genesis/block.v7.json
cp "${PROJECT_PATH}"/build/dummy.block.v7.json ./genesis/block.v7.json
fi
ok "Genesis Block successfully created"
fi
running "Creating diva.yml file"
tsc
JOIN_NETWORK=${JOIN_NETWORK} \
SIZE_NETWORK=${SIZE_NETWORK} \
BASE_DOMAIN=${BASE_DOMAIN} \
BASE_IP=${BASE_IP} \
PORT=${PORT} \
NODE_ENV=${NODE_ENV} \
LOG_LEVEL=${LOG_LEVEL} \
IS_TESTNET=${IS_TESTNET} \
node "${PROJECT_PATH}"/dist/build.js
ok "Created diva.yml file"