Last active
February 17, 2021 21:39
-
-
Save ICONationTeam/c50e9d9a036b97fe7d0a7e9c04c3d918 to your computer and use it in GitHub Desktop.
build_and_start.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Cleaning..." | |
rm -rf ./dist/ | |
killall goloop | |
killall java | |
pkill java | |
# Globals | |
BASE_DIR=$(dirname $0) | |
JAVAEE_VERSION=$(grep "^VERSION=" ./javaee/gradle.properties | cut -d= -f2) | |
echo "Building native Client..." | |
build_native_client() { | |
cd javaee/exec/src/native/ | |
mkdir -p ../../build/native/ | |
gcc -O3 -fPIC -Wall -I/usr/lib/jvm/java-11-openjdk-amd64/include -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/ -c -o ../../build/native/Client.o Client.c | |
gcc -shared -o ../../build/native/libclient.so ../../build/native/Client.o | |
cd - > /dev/null | |
} | |
build_native_client | |
echo "Building gstool..." | |
build_gstool() { | |
make gstool | |
} | |
build_gstool | |
echo "Building goloop..." | |
build_image() { | |
cd ./javaee | |
./gradlew build | |
cd ../ | |
local SRC_DIR="." | |
local BUILD_DIR=${BASE_DIR} | |
BIN_DIR=${BIN_DIR:-${SRC_DIR}/bin} | |
if [ "${GOBUILD_TAGS}" != "" ] ; then | |
GOLOOP_VERSION="${GOLOOP_VERSION}-tags(${GOBUILD_TAGS})" | |
fi | |
# copy required files to ${BUILD_DIR}/dist | |
echo "BUILD_DIR=${BUILD_DIR}" | |
rm -rf ${BUILD_DIR}/dist | |
mkdir -p ${BUILD_DIR}/dist/bin/ | |
cp ${BIN_DIR}/goloop ${BUILD_DIR}/dist/bin/ | |
cp -f ${BIN_DIR}/gstool ${BUILD_DIR}/dist/bin/ | |
cp ${SRC_DIR}/javaee/app/execman/build/distributions/execman-${JAVAEE_VERSION}-SNAPSHOT.zip ${BUILD_DIR}/dist/execman-${JAVAEE_VERSION}-SNAPSHOT.zip | |
} | |
build_image | |
echo "Installing JavaEE..." | |
install_javaee() { | |
mkdir -p ./goloop/bin | |
rm -rf ./goloop/execman* | |
cp dist/execman-${JAVAEE_VERSION}-SNAPSHOT.zip ./goloop/ | |
unzip -q ./goloop/execman-${JAVAEE_VERSION}-SNAPSHOT.zip -d ./goloop/ | |
mv -f ./goloop/execman-${JAVAEE_VERSION}-SNAPSHOT ./goloop/execman | |
rm -f ./goloop/execman-*.zip | |
cp javaee/exec/build/native/* ./goloop/execman/native/ | |
} | |
install_javaee | |
export JAVAEE_BIN=${PWD}/goloop/execman/bin/execman | |
# install goloop and other stuff | |
install_goloop() { | |
cp dist/bin/* ./goloop/bin/ | |
export PATH=$PATH:${PWD}/goloop/bin | |
mkdir -p data | |
} | |
install_goloop | |
# Init goloop | |
init_goloop() { | |
export GOLOOP_DATA_ROOT=${PWD}/goloop/data | |
export GOLOOP_NODE_DIR=${PWD}/goloop/data | |
export GOLOOP_CONFIG=${PWD}/goloop/config/server.json | |
export GOLOOP_KEY_STORE=${PWD}/goloop/config/keystore.json | |
export GOLOOP_KEY_SECRET=${PWD}/goloop/config/keysecret | |
export GOLOOP_P2P_LISTEN=":8080" | |
export GOLOOP_RPC_ADDR=":9082" | |
export GOLOOP_ENGINES=java | |
export GOLOOP_LOGFILE="${PWD}/logs/goloop.log" | |
cd ./goloop | |
echo "Entrypoint..." | |
if [ "$GOLOOP_CONFIG" != "" ] && [ ! -f "$GOLOOP_CONFIG" ]; then | |
UNSET="GOLOOP_CONFIG" | |
CMD="goloop server save $GOLOOP_CONFIG" | |
if [ "$GOLOOP_KEY_SECRET" != "" ] && [ ! -f "$GOLOOP_KEY_SECRET" ]; then | |
mkdir -p $(dirname $GOLOOP_KEY_SECRET) | |
echo -n $(date|md5sum|head -c16) > $GOLOOP_KEY_SECRET | |
fi | |
if [ "$GOLOOP_KEY_STORE" != "" ] && [ ! -f "$GOLOOP_KEY_STORE" ]; then | |
UNSET="$UNSET GOLOOP_KEY_STORE" | |
CMD="$CMD --save_key_store=$GOLOOP_KEY_STORE" | |
fi | |
sh -c "unset $UNSET ; $CMD" | |
fi | |
if [ "${GOLOOP_LOGFILE}" != "" ]; then | |
GOLOOP_LOGDIR=$(dirname ${GOLOOP_LOGFILE}) | |
if [ ! -d "${GOLOOP_LOGDIR}" ]; then | |
mkdir -p ${GOLOOP_LOGDIR} | |
touch ${GOLOOP_LOGFILE} | |
fi | |
fi | |
echo "Starting goloop now..." | |
goloop server start > ${GOLOOP_LOGFILE} 2>&1 & | |
} | |
init_goloop | |
# Init genesis | |
init_genesis() { | |
echo "Creating genesis storage..." | |
./bin/goloop ks gen -o god.json | |
./bin/goloop gn gen -o genesis.json -g god.json ./config/keystore.json --fee icon | |
./bin/goloop gs gen -o gs.zip -i genesis.json | |
sleep 1 | |
} | |
init_genesis | |
join_chain() { | |
echo "Joining the chain..." | |
export nid=$(./bin/goloop -c ./config/keystore.json chain join --genesis gs.zip --seed server0:8080) | |
echo "NID=${nid}" | |
echo ${nid} > nid | |
} | |
join_chain | |
# Let's go! | |
echo "Starting the chain!" | |
./bin/goloop -c ./config/server.json chain start ${nid} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment