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.servicePackage.TemplateService.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+
24+ # set defaults for optional service parameters
25+ [[ -z " ${SERVICE_PASSPHRASE} " ]] && export SERVICE_PASSPHRASE=' template'
26+
27+ # wait for any bootstrap host to be available
28+ if [[ ! -z " ${BOOTSTRAP} " ]]; then
29+ echo " Waiting for any bootstrap host to become available..."
30+ for host_port in ${BOOTSTRAP// ,/ } ; do
31+ arr_host_port=(${host_port//:/ } )
32+ host=${arr_host_port[0]}
33+ port=${arr_host_port[1]}
34+ if { < /dev/tcp/${host} /${port} ; } 2> /dev/null; then
35+ echo " ${host_port} is available. Continuing..."
36+ break
37+ fi
38+ done
39+ fi
40+ # prevent glob expansion in lib/*
41+ set -f
42+ 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} "
43+ if [[ ! -z " ${BOOTSTRAP} " ]]; then
44+ LAUNCH_COMMAND=" ${LAUNCH_COMMAND} -b ${BOOTSTRAP} "
45+ fi
46+
47+ # it's realistic for different nodes to use different accounts (i.e., to have
48+ # different node operators). this function echos the N-th mnemonic if the
49+ # variable WALLET is set to N. If not, first mnemonic is used
50+ function selectMnemonic {
51+ 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" )
52+ if [[ ${WALLET} =~ ^[0-9]+$ && ${WALLET} -lt ${# mnemonics[@]} ]]; then
53+ # get N-th mnemonic
54+ echo " ${mnemonics[${WALLET}]} "
55+ else
56+ # note: zsh and others use 1-based indexing. this requires bash
57+ echo " ${mnemonics[0]} "
58+ fi
59+ }
60+
61+ # prepare pastry properties
62+ echo external_address = $( curl -s https://ipinfo.io/ip) :${LAS2PEER_PORT} > etc/pastry.properties
63+
64+ # start the service within a las2peer node
65+ if [[ -z " ${@ } " ]]
66+ then
67+ if [ -n " $LAS2PEER_ETH_HOST " ]; then
68+ 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()"
69+ else
70+ exec ${LAUNCH_COMMAND} --node-id-seed $NODE_ID_SEED --observer uploadStartupDirectory startService\( " '" " ${SERVICE} " " '" , " '" " ${SERVICE_PASSPHRASE} " " '" \) startWebConnector
71+ fi
72+ else
73+ exec ${LAUNCH_COMMAND} ${@ }
74+ fi
0 commit comments