forked from StakeSquid/graphprotocol-combined-docker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
start-indexer
executable file
·167 lines (128 loc) · 4.92 KB
/
start-indexer
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
#!/bin/bash
ENV_FILE=".env"
# List of packages to check
packages=("docker.io" "docker-compose" "bc" "git" "curl" "httpie" "jq" "nano" "wget" "bsdmainutils" "base58" "netcat" "net-tools" "apache2-utils")
# Loop through the list of packages
for package in "${packages[@]}"; do
# Check if the package is installed
if dpkg -s "$package" | grep -q "install ok installed"; then
echo -n ""
else
sudo apt install -y $package
fi
done
[ ! -f $ENV_FILE ] && cp env-template $ENV_FILE
set -a
source <(cat "$ENV_FILE" | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
set +a
has_param() {
local term="$1"
shift
for arg; do
if [[ $arg == "$term" ]]; then
return 0
fi
done
return 1
}
[ ! -f init/hostname ] && (cd init && bash generate-hostname.sh)
[ ! -f init/geolocation ] && (cd init && bash generate-geolocation.sh)
[ ! -f init/upstreams ] && (cd init && bash generate-upstreams.sh)
[ -z "$DOMAIN" ] && DOMAIN=$(cat init/hostname) && sed -i "s/DOMAIN=.*/[email protected]/" "$ENV_FILE"
[ -z "$EMAIL" ] && sed -i "s/EMAIL=.*/[email protected]/" "$ENV_FILE"
[ -z "$ADMIN_PASSWORD" ] && ADMIN_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo) && sed -i "s/ADMIN_PASSWORD=.*/ADMIN_PASSWORD=$ADMIN_PASSWORD/" "$ENV_FILE"
[ -z "$DB_PASS" ] && DB_PASS=$(date +%s | sha256sum | base64 | head -c 32 ; echo) && sed -i "s/DB_PASS=.*/DB_PASS=$DB_PASS/" "$ENV_FILE"
[ -z "$GEO_COORDINATES" ] && GEO_COORDINATES=$(cat init/geolocation) && sed -i "s/GEO_COORDINATES=.*/GEO_COORDINATES=$GEO_COORDINATES/" "$ENV_FILE"
if [ -z "$OPERATOR_SEED_PHRASE_MAINNET" ] && has_param '-m' "$@"
then
echo -e "\e[1;32m Please enter your operator seed phrase for mainnet: \e[0m"
read OPERATOR_SEED_PHRASE_MAINNET
sed -i "s/OPERATOR_SEED_PHRASE_MAINNET=.*/OPERATOR_SEED_PHRASE_MAINNET=$OPERATOR_SEED_PHRASE_MAINNET/" "$ENV_FILE"
fi
if [ -z "$STAKING_WALLET_ADDRESS_MAINNET" ] && has_param '-m' "$@"
then
[ ! -f init/staking-wallet-mainnet ] && (cd init && bash generate-staking-wallet-mainnet.sh "$OPERATOR_SEED_PHRASE_MAINNET")
STAKING_WALLET_ADDRESS_MAINNET=$(cat init/staking-wallet-mainnet)
sed -i "s/STAKING_WALLET_ADDRESS_MAINNET=.*/STAKING_WALLET_ADDRESS_MAINNET=$STAKING_WALLET_ADDRESS_MAINNET/" "$ENV_FILE"
fi
if [ -z "$OPERATOR_SEED_PHRASE_TESTNET" ] && has_param '-t' "$@"
then
echo -e "\e[1;32m Please enter your operator seed phrase for testnet: \e[0m"
read OPERATOR_SEED_PHRASE_TESTNET
sed -i "s/OPERATOR_SEED_PHRASE_TESTNET=.*/OPERATOR_SEED_PHRASE_TESTNET=$OPERATOR_SEED_PHRASE_TESTNET/" "$ENV_FILE"
fi
if [ -z "$STAKING_WALLET_ADDRESS_TESTNET" ] && has_param '-t' "$@"
then
[ ! -f init/staking-wallet-testnet ] && (cd init && bash generate-staking-wallet-testnet.sh "$OPERATOR_SEED_PHRASE_TESTNET")
STAKING_WALLET_ADDRESS_TESTNET=$(cat init/staking-wallet-testnet)
sed -i "s/STAKING_WALLET_ADDRESS_TESTNET=.*/STAKING_WALLET_ADDRESS_TESTNET=$STAKING_WALLET_ADDRESS_TESTNET/" "$ENV_FILE"
fi
if [ -z "$UPSTREAM_RPCS" ]
then
[ ! -f init/upstreams ] && (cd init && bash generate-upstreams.sh)
UPSTREAM_RPCS=$(cat init/upstreams)
ESCAPED_UPSTREAM_RPCS=$(printf '%s\n' "$UPSTREAM_RPCS" | sed -e 's/[\/&]/\\&/g')
sed -i "s/UPSTREAM_RPCS=.*/UPSTREAM_RPCS=$ESCAPED_UPSTREAM_RPCS/" "$ENV_FILE"
fi
# generate the graph-node config file
docker run -v $(pwd)/graph-node-configs:/configs --env-file="$ENV_FILE" bhgedigital/envsubst sh -c "envsubst < configs/config.tmpl > configs/config.toml"
# contruct the docker compose file from pieces
joinByChar() {
local IFS="$1"
shift
echo "$*"
}
arrVar=("base.yml" "monitoring.yml" "stakesquid-rpc.yml" )
if has_param '--external-database' "$@";
then
[ -z "$DB_HOST" ] && echo "Please edit the $ENV_FILE to configure your external database manually."
else
arrVar+=("database.yml")
if has_param '-t' "$@";
then
arrVar+=("testnet-agent-database.yml")
fi
if has_param '-m' "$@";
then
arrVar+=("mainnet-agent-database.yml")
fi
fi
if has_param '-t' "$@";
then
arrVar+=("testnet.yml")
fi
if has_param '-m' "$@";
then
arrVar+=("mainnet.yml")
fi
sed -i "s/COMPOSE_FILE=.*/COMPOSE_FILE=$(joinByChar ':' ${arrVar[@]})/" "$ENV_FILE"
# delete config params from our list of parameters for docker-compose
bash_start_params=(-t -m --external-database)
docker_compose_params=$@
for del in ${bash_start_params[@]}
do
docker_compose_params=("${docker_compose_params[@]/$del}") #Quotes when working with strings
done
docker-compose up -d --remove-orphans --build ${docker_compose_params[@]}
if has_param '-m' "$@";
then
echo " "
echo " "
echo "Your dashboard for mainnet:"
echo " "
echo "$DOMAIN/grafana-mainnet"
fi
if has_param '-t' "$@";
then
echo " "
echo " "
echo "Your dashboard for testnet:"
echo " "
echo "$DOMAIN/grafana-testnet"
fi
echo " "
echo " "
echo "Admin: $ADMIN_USER"
echo "Password: $ADMIN_PASSWORD"
echo " "
echo " "