1+ #! /usr/bin/env bash
2+
3+ set -e
4+
5+ # print all comands to console if DEBUG is set
6+ if [[ ! -z " ${DEBUG} " ]]; then
7+ set -x
8+ fi
9+ NODE_ID_SEED=${NODE_ID_SEED:- $RANDOM }
10+
11+ # set some helpful variables
12+ export SERVICE_PROPERTY_FILE=' etc/i5.las2peer.services.apiTestingBot.APITestingBot.properties'
13+ export WEB_CONNECTOR_PROPERTY_FILE=' etc/i5.las2peer.connectors.webConnector.WebConnector.properties'
14+ export SERVICE_VERSION=$( awk -F " =" ' /service.version/ {print $2}' gradle.properties)
15+ export SERVICE_NAME=$( awk -F " =" ' /service.name/ {print $2}' gradle.properties)
16+ export SERVICE_CLASS=$( awk -F " =" ' /service.class/ {print $2}' gradle.properties)
17+ export SERVICE=${SERVICE_NAME} .${SERVICE_CLASS} @${SERVICE_VERSION}
18+
19+ function set_in_service_config {
20+ sed -i " s?${1} [[:blank:]]*=.*?${1} =${2} ?g" ${SERVICE_PROPERTY_FILE}
21+ }
22+
23+ function set_in_web_config {
24+ sed -i " s?${1} [[:blank:]]*=.*?${1} =${2} ?g" ${WEB_CONNECTOR_PROPERTY_FILE}
25+ }
26+ set_in_web_config httpPort ${HTTP_PORT}
27+ set_in_web_config httpsPort ${HTTPS_PORT}
28+
29+ # check mandatory variables
30+ [[ -z " ${BOT_MANAGER_URL} " ]] && \
31+ echo " Mandatory variable BOT_MANAGER_URL is not set. Add -e BOT_MANAGER_URL=... to your arguments." && exit 1
32+
33+ set_in_service_config botManagerURL ${BOT_MANAGER_URL}
34+
35+
36+ # set defaults for optional service parameters
37+ [[ -z " ${SERVICE_PASSPHRASE} " ]] && export SERVICE_PASSPHRASE=' template'
38+
39+ # wait for any bootstrap host to be available
40+ if [[ ! -z " ${BOOTSTRAP} " ]]; then
41+ echo " Waiting for any bootstrap host to become available..."
42+ for host_port in ${BOOTSTRAP// ,/ } ; do
43+ arr_host_port=(${host_port//:/ } )
44+ host=${arr_host_port[0]}
45+ port=${arr_host_port[1]}
46+ if { < /dev/tcp/${host} /${port} ; } 2> /dev/null; then
47+ echo " ${host_port} is available. Continuing..."
48+ break
49+ fi
50+ done
51+ fi
52+ # prevent glob expansion in lib/*
53+ set -f
54+ LAUNCH_COMMAND=' java -cp lib/* --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED i5.las2peer.tools.L2pNodeLauncher -s service -p ' " ${LAS2PEER_PORT} ${SERVICE_EXTRA_ARGS} "
55+ if [[ ! -z " ${BOOTSTRAP} " ]]; then
56+ LAUNCH_COMMAND=" ${LAUNCH_COMMAND} -b ${BOOTSTRAP} "
57+ fi
58+
59+ # it's realistic for different nodes to use different accounts (i.e., to have
60+ # different node operators). this function echos the N-th mnemonic if the
61+ # variable WALLET is set to N. If not, first mnemonic is used
62+ function selectMnemonic {
63+ declare -a mnemonics=(" differ employ cook sport clinic wedding melody column pave stuff oak price" " memory wrist half aunt shrug elbow upper anxiety maximum valve finish stay" " alert sword real code safe divorce firm detect donate cupboard forward other" " pair stem change april else stage resource accident will divert voyage lawn" " lamp elbow happy never cake very weird mix episode either chimney episode" " cool pioneer toe kiwi decline receive stamp write boy border check retire" " obvious lady prize shrimp taste position abstract promote market wink silver proof" " tired office manage bird scheme gorilla siren food abandon mansion field caution" " resemble cattle regret priority hen six century hungry rice grape patch family" " access crazy can job volume utility dial position shaft stadium soccer seven" )
64+ if [[ ${WALLET} =~ ^[0-9]+$ && ${WALLET} -lt ${# mnemonics[@]} ]]; then
65+ # get N-th mnemonic
66+ echo " ${mnemonics[${WALLET}]} "
67+ else
68+ # note: zsh and others use 1-based indexing. this requires bash
69+ echo " ${mnemonics[0]} "
70+ fi
71+ }
72+
73+ # prepare pastry properties
74+ echo external_address = $( curl -s https://ipinfo.io/ip) :${LAS2PEER_PORT} > etc/pastry.properties
75+
76+ # start the service within a las2peer node
77+ if [[ -z " ${@ } " ]]
78+ then
79+ if [ -n " $LAS2PEER_ETH_HOST " ]; then
80+ exec ${LAUNCH_COMMAND} --node-id-seed $NODE_ID_SEED --observer --ethereum-mnemonic " $( selectMnemonic) " uploadStartupDirectory startService\( " '" " ${SERVICE} " " '" , " '" " ${SERVICE_PASSPHRASE} " " '" \) startWebConnector " node=getNodeAsEthereumNode()" " registry=node.getRegistryClient()" " n=getNodeAsEthereumNode()" " r=n.getRegistryClient()"
81+ else
82+ exec ${LAUNCH_COMMAND} --node-id-seed $NODE_ID_SEED --observer uploadStartupDirectory startService\( " '" " ${SERVICE} " " '" , " '" " ${SERVICE_PASSPHRASE} " " '" \) startWebConnector
83+ fi
84+ else
85+ exec ${LAUNCH_COMMAND} ${@ }
86+ fi
0 commit comments