-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalert_lib.sh
executable file
·68 lines (62 loc) · 2.1 KB
/
alert_lib.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
run_by_cron=$1
function log {
fullpath=$0
filename=${fullpath##*/}
filename_short=${filename%.*}
[[ "$run_by_cron" == "-c" ]] && /usr/bin/logger -t "$filename_short[$$]" "$*"
[[ "$run_by_cron" != "-c" ]] && echo "$*"
}
function verbose {
[[ $SETZER_VERBOSE ]] && log "[V] $*"
}
function checketh {
# Global configuration
if [[ -e /etc/setzer.conf ]]; then
# shellcheck source=/dev/null
. "/etc/setzer.conf"
fi
# Check if connected to node
export RPC_TIMEOUT=${RPC_TIMEOUT:-30s}
unset ETH_RPC_URL
for port in ${RPC_PORTS:-8545}; do
export ETH_RPC_PORT=$port
log "Trying on rpc port $ETH_RPC_PORT."
[[ "$(/usr/local/bin/setzer connected)" == "true" ]] && running_client="$((running_client+1))" && log "Node running on RPC port $ETH_RPC_PORT." && ok=true
done
for url in $RPC_URLS; do
export ETH_RPC_URL=$url
log "Trying on rpc url $ETH_RPC_URL"
[[ "$(/usr/local/bin/setzer connected)" == "true" ]] && running_client="$((running_client+1))" && log "Node running on RPC url $ETH_RPC_URL."
done
[[ "$ok" == "true" ]] && unset ETH_RPC_URL
}
function getnode {
# Global configuration
if [[ -e /etc/setzer.conf ]]; then
# shellcheck source=/dev/null
. "/etc/setzer.conf"
fi
unset ETH_RPC_URL
# check we're connected to ethereum
while [[ "$(/usr/local/bin/setzer connected)" != "true" ]]; do
unset ETH_RPC_URL
for port in ${RPC_PORTS:-8545}; do
export ETH_RPC_PORT=$port
log "Trying on rpc port $ETH_RPC_PORT."
[[ "$(/usr/local/bin/setzer connected)" == "true" ]] && ok=true && break
done
if [[ "$ok" != "true" ]]; then
for url in $RPC_URLS; do
export ETH_RPC_URL=$url
log "Trying on rpc url $ETH_RPC_URL"
[[ "$(/usr/local/bin/setzer connected)" == "true" ]] && url_ok=true && break
done
[[ "$ok" == "true" ]] && unset ETH_RPC_URL
[[ "$url_ok" == "true" ]] && ok=true
fi
[[ "$ok" != "true" ]] && log "Not connected to Ethereum, retry in 10 seconds..." && sleep 10
done
echo $ETH_RPC_URL
[[ -z "$ETH_RPC_URL" ]] && log "Node running on rpc port ${ETH_RPC_PORT:-8545}."
[[ -n "$ETH_RPC_URL" ]] && log "Node running on rpc url $ETH_RPC_URL."
}