From 2f0ca0da1b60c0637a3ad5daa2bd0751ebd74dd9 Mon Sep 17 00:00:00 2001 From: Dmitriy Gerasimov <naeper@demlabs.net> Date: Mon, 15 Mar 2021 15:34:19 +0700 Subject: [PATCH] [*] Splitting scripts between common-usage and platform-specific --- CMakeLists.txt | 48 ++++-- .../share/configs/dapcash-node.cfg.tpl | 0 .../configs/network/dapcash-testnet.cfg.tpl | 0 {dist => dist.linux}/share/apt/demlabskey.gpg | 0 dist.linux/share/configs/dapcash-node.cfg.tpl | 140 ++++++++++++++++++ .../configs/network/dapcash-testnet.cfg.tpl | 31 ++++ .../share/dapcash-node.service | 0 .../share/logrotate/dapcash-node | 0 dist/share/profile.d/dapcash-node.sh | 2 - scripts.darwin/create_configs.sh | 19 +++ scripts/.gitkeep | 0 scripts/create_configs_from_tpl.sh | 67 +++++++++ sources/main.c | 3 +- 13 files changed, 297 insertions(+), 13 deletions(-) rename {dist => dist.darwin}/share/configs/dapcash-node.cfg.tpl (100%) rename {dist => dist.darwin}/share/configs/network/dapcash-testnet.cfg.tpl (100%) rename {dist => dist.linux}/share/apt/demlabskey.gpg (100%) create mode 100644 dist.linux/share/configs/dapcash-node.cfg.tpl create mode 100644 dist.linux/share/configs/network/dapcash-testnet.cfg.tpl rename {dist => dist.linux}/share/dapcash-node.service (100%) rename {dist => dist.linux}/share/logrotate/dapcash-node (100%) delete mode 100755 dist/share/profile.d/dapcash-node.sh create mode 100644 scripts.darwin/create_configs.sh delete mode 100644 scripts/.gitkeep create mode 100755 scripts/create_configs_from_tpl.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index d737590..647aca6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,9 +37,21 @@ add_subdirectory(cellframe-sdk) if(UNIX) if(DARWIN) - SET(CMAKE_INSTALL_PREFIX "/usr/local/DapCashNode") - SET(CPACK_INSTALL_PREFIX "/usr/local/DapCashNode") - SET(DESTDIR "/usr/local/DapCashNode") + SET(CMAKE_INSTALL_PREFIX "/Applications/DapCash.app") + SET(CPACK_INSTALL_PREFIX "/Applications/DapCash.app") + SET(DESTDIR "/Applications/DapCash.app") + + set(BUNDLE_NAME "DapCash.app") + set(BUNDLE_PATH "${CMAKE_INSTALL_PREFIX}") + set(BINDIR ${BUNDLE_PATH}/Contents/MacOS) + set(LIBDIR ${BUNDLE_PATH}) + set(RLIBDIR ${BUNDLE_PATH}/Contents/Frameworks) + set(SHAREDIR ${BUNDLE_PATH}/Contents/Resources) + set(PLUGINSDIR ${BUNDLE_PATH}/Contents/PlugIns) + set(IMPORTSDIR ${BINDIR}) + + + add_definitions("-DDAP_DARWIN_LIBRARY") else() SET(CMAKE_INSTALL_PREFIX "/opt/${PROJECT_NAME}") SET(CPACK_INSTALL_PREFIX "/opt/${PROJECT_NAME}") @@ -186,13 +198,31 @@ if(NOT ANDROID) target_include_directories(${NODE_TOOL_TARGET} INTERFACE .) endif() -INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) +if(DARWIN) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${SHAREDIR} FILES_MATCHING PATTERN "*" PATTERN "*") + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.darwin/ DESTINATION ${SHAREDIR} FILES_MATCHING PATTERN "*" PATTERN "*") + INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR} ) + INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${BINDIR} ) + INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${BINDIR} ) + + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ DESTINATION ${BINDIR} FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ ) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts.darwin/ DESTINATION ${BINDIR} FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ ) + +else() + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") + if(LINUX) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.linux/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") + elseif(BSD) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist.bsd/ DESTINATION ${CMAKE_INSTALL_PREFIX} FILES_MATCHING PATTERN "*" PATTERN "*") + endif() + INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) + + if(UNIX AND NOT ANDROID) + INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) + INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) + endif() -if(UNIX AND NOT ANDROID) - INSTALL(TARGETS ${NODE_CLI_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) - INSTALL(TARGETS ${NODE_TOOL_TARGET} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin ) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ ) endif() -INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ DESTINATION ${CMAKE_INSTALL_PREFIX}/sbin FILES_MATCHING PATTERN "*" PATTERN "*" PERMISSIONS OWNER_EXECUTE;OWNER_READ;OWNER_WRITE;WORLD_READ;GROUP_READ ) INCLUDE(CPack) diff --git a/dist/share/configs/dapcash-node.cfg.tpl b/dist.darwin/share/configs/dapcash-node.cfg.tpl similarity index 100% rename from dist/share/configs/dapcash-node.cfg.tpl rename to dist.darwin/share/configs/dapcash-node.cfg.tpl diff --git a/dist/share/configs/network/dapcash-testnet.cfg.tpl b/dist.darwin/share/configs/network/dapcash-testnet.cfg.tpl similarity index 100% rename from dist/share/configs/network/dapcash-testnet.cfg.tpl rename to dist.darwin/share/configs/network/dapcash-testnet.cfg.tpl diff --git a/dist/share/apt/demlabskey.gpg b/dist.linux/share/apt/demlabskey.gpg similarity index 100% rename from dist/share/apt/demlabskey.gpg rename to dist.linux/share/apt/demlabskey.gpg diff --git a/dist.linux/share/configs/dapcash-node.cfg.tpl b/dist.linux/share/configs/dapcash-node.cfg.tpl new file mode 100644 index 0000000..3db955b --- /dev/null +++ b/dist.linux/share/configs/dapcash-node.cfg.tpl @@ -0,0 +1,140 @@ +# General section +[general] +# General debug mode +debug_mode={DEBUG_MODE} +# Debug stream packets +debug_dump_stream_headers=false +# Debug I/O reactor, false by default +#debug_reactor=false +# Debug HTTP protocol, false by default +#debug_http=false + +# seed mode. WARNING. Used true only when you start the new network +#seed_mode=false + +# Auto bring up links and sync everything over them +auto_online={AUTO_ONLINE} + +# Server part +[server] +# By default you don't need to open you to the world +enabled={SERVER_ENABLED} +news_url_enabled=false +bugreport_url_enabled=false +listen_address={SERVER_ADDR} +listen_port_tcp={SERVER_PORT} + +# External IPv4 address +#ext_address=8.9.10.11 +# External IPv6 address +#ext_address6=aaaa:bbbb:deee:96ff:feee:3fff +# +# If not set - used listen_port_tcp for node table auto fill +#ext_port_tcp=8089 + +# Build in DNS client (need for bootstraping) +[dns_client] +#request_timeout=10 + +# Builtin DNS server +[dns_server] +# enabled=false +#bootstrap_balancer=false + +# Ledger defaults +[ledger] +# More debug output +# debug_more=true + +# DAG defaults +[dag] +# More debug output +# debug_more=true + +[srv] +order_signed_only=false + +[srv_dns] +enabled=false +pricelist=[] + +# Mempool +[mempool] +# Automaticaly should be true for master ad root node role +# auto_proc=false + +# DAP network protocol client +[dap_client] +#debug_more=false +#timeout=10 +#timeout_read_after_connect=5 +#max_tries=5 + +# Chain network settings +[chain_net] +# debug_more=true +# Timeout for network status wait +# status_wait_timeout=10 + +[stream_ch_chain] +# Uncomment to have more debug information in stream channel Chain +# False by default +#debug_more=true + +# Number of hashes packed into the one update packet +# Increase it to reduce update latency +# Decrease if bad networking +# update_pack_size=100 + + +# Central Dataase +[cdb] +enabled=false +servers_list_enabled=false +servers_list_networks=[dapcash-testnet] + +# Central Database authorization +[cdb_auth] +enabled=false +domain=mydomain +# auth mode=passwd[default] or serial +mode=passwd +registration_open=true +tx_cond_create=false +# List of condition templates, created for authorized users. Format of condition: +# <wallet name>:<Value per transaction>:<Minimum time(seconds) between transactions>:<network name> +# tx_cond_templates=[mywallet0:0.00001:3600:DAPT:dapcash-testnet,mywallet1:0.000001:3600:KELT:dapcash-testnet] + +# VPN stream channel processing module +[srv_vpn] +# Turn to true if you want to share VPN service from you node +enabled=false +geoip_enabled=false +debug_more=false +# Grace period for service , 60 second by default +#grace_period=60 +# List of loca security access groups. Built in: expats,admins,services,nobody,everybody +network_address=10.11.12.0 +network_mask=255.255.255.0 +pricelist=[dapcash-testnet:100:DAPT:3600:SEC:mywallet0,dapcash-testnet:100:DAPB:3600:SEC:mywallet1] + +# Console interface server +[conserver] +enabled=true +#listen_port_tcp=12345 +listen_unix_socket_path=/opt/dapcash-node/var/run/node_cli +# Default permissions 770 +#listen_unix_socket_permissions=770 + +# Application Resources +[resources] +# 0 means auto detect +threads_cnt=0 +pid_path=/opt/dapcash-node/var/run/dapcash-node.pid +log_file=/opt/dapcash-node/var/log/dapcash-node.log +wallets_path=/opt/dapcash-node/var/lib/wallet +geoip_db_path=share/geoip/GeoLite2-City.mmdb +ca_folders=[/opt/dapcash-node/var/lib/ca,/opt/dapcash-node/share/ca] +dap_global_db_path=/opt/dapcash-node/var/lib/global_db +dap_global_db_driver=cdb + diff --git a/dist.linux/share/configs/network/dapcash-testnet.cfg.tpl b/dist.linux/share/configs/network/dapcash-testnet.cfg.tpl new file mode 100644 index 0000000..7427dce --- /dev/null +++ b/dist.linux/share/configs/network/dapcash-testnet.cfg.tpl @@ -0,0 +1,31 @@ +# DapCash testing network +# General section +[general] +id=0x0000000007654321 +name=dapcash-testnet +# Possible values: light, full, archive, master, root +node-role={NODE_TYPE} +#node-alias=addr-%node_addr% +#node-addr=1234::1234::1234::1234 +gdb_groups_prefix=dapcash-testnet +# node addr exired time in hours (168h=1w 720h=1m 8760h=1y), by default 720h(1week) +#node-addr=0x10 +#node-addr-expired=168 +# type of node addr [auto, static, dinamic] +node_addr_type=auto +default_chain=bronze + +seed_nodes_hostnames=[0.seed.testnet.dapcash.org,1.seed.testnet.dapcash.org,2.seed.testnet.dapcash.org] +seed_nodes_aliases=[dapcash.testnet.root.0,dapcash.testnet.root.1,dapcash.testnet.root.2] +seed_nodes_addrs=[ffff::0000::0000::0001,ffff::0000::0000::0002,ffff::0000::0000::0003] +seed_nodes_port=[80,80,80] + +#[role-master] +#proc_chains=[0x00000001] + +#[dag-poa] +#events-sign-cert=mycert + +#[dag-pos] +#events-sign-wallet=mywallet + diff --git a/dist/share/dapcash-node.service b/dist.linux/share/dapcash-node.service similarity index 100% rename from dist/share/dapcash-node.service rename to dist.linux/share/dapcash-node.service diff --git a/dist/share/logrotate/dapcash-node b/dist.linux/share/logrotate/dapcash-node similarity index 100% rename from dist/share/logrotate/dapcash-node rename to dist.linux/share/logrotate/dapcash-node diff --git a/dist/share/profile.d/dapcash-node.sh b/dist/share/profile.d/dapcash-node.sh deleted file mode 100755 index 62423c4..0000000 --- a/dist/share/profile.d/dapcash-node.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -export PATH="$PATH:/opt/dapcash-node/bin:/opt/dapcash-node/sbin" diff --git a/scripts.darwin/create_configs.sh b/scripts.darwin/create_configs.sh new file mode 100644 index 0000000..7b76dca --- /dev/null +++ b/scripts.darwin/create_configs.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# Global settings +export DAP_PREFIX=/Applications/DapCash.app/Contents/Resources +export DAP_APP_NAME=dapcash-node +export DAP_CHAINS_NAME=dapcash +export DAP_CFG_TPL=/Applications/DapCash.app/Contents/Resources/share/configs/$DAP_APP_NAME.cfg.tpl + +# Values +export DAP_DEBUG_MODE=false +export DAP_AUTO_ONLINE=true +export DAP_SERVER_ENABLED=false +export DAP_SERVER_ADDRESS=0.0.0.0 +export DAP_SERVER_PORT=8089 + +# DapCash testnet +export DAP_DAPCASH_TESTNET_ENABLED=true +export DAP_DAPCASH_TESTNET_ROLE=full + +./create_configs_from_tpl.sh \ No newline at end of file diff --git a/scripts/.gitkeep b/scripts/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/create_configs_from_tpl.sh b/scripts/create_configs_from_tpl.sh new file mode 100755 index 0000000..cfdbb49 --- /dev/null +++ b/scripts/create_configs_from_tpl.sh @@ -0,0 +1,67 @@ +#!/bin/bash -e +if [ ! -d "$DAP_PREFIX" ]; then + echo "Need to export proper DAP_PREFIX as prefix path for this scripts" + exit 2 +fi + +if [ ! "$DAP_APP_NAME" ]; then + echo "Need to export DAP_APP_NAME for this scripts" + exit 3 +fi + +if [ ! "$DAP_CHAINS_NAME" ]; then + echo "Need to export DAP_CHAINS_NAME for this scripts" + exit 4 +fi + +# set default values +[ "$DAP_DEBUG_MODE_NAME" ] || DAP_DEBUG_MODE="false" +[ "$DAP_AUTO_ONLINE" ] || DAP_AUTO_ONLINE="true" +[ "$DAP_SERVER_ENABLED" ] || DAP_SERVER_ENABLED="false" +[ "$DAP_SERVER_PORT" ] || DAP_SERVER_PORT="8079" +[ "$DAP_SERVER_ADDR" ] || DAP_SERVER_ADDR="0.0.0.0" +[ "$DAP_DAPCASH_TESTNET_ENABLED" ] || DAP_DAPCASH_TESTNET_ENABLED="true" +[ "$DAP_DAPCASH_TESTNET_ROLE" ] || DAP_DAPCASH_TESTNET_ROLE="full" + + +DAP_CFG_TPL="$DAP_PREFIX/share/configs//$DAP_APP_NAME.cfg.tpl" + + + +# Init node config +if [ ! -e "$DAP_CFG" ]; then + DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg" +fi + +if [ -e "$DAP_CFG" ]; then + DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg.new" +else + DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg" +fi + +cat $DAP_CFG_TPL > $DAP_CFG || true +sed -i .old "s/{DEBUG_MODE}/$DAP_DEBUG_MODE /" $DAP_CFG || true +sed -i .old "s/{AUTO_ONLINE}/$DAP_AUTO_ONLINE/" $DAP_CFG || true +sed -i .old "s/{SERVER_ENABLED}/$DAP_SERVER_ENABLED/" $DAP_CFG || true +sed -i .old "s/{SERVER_PORT}/$DAP_SERVER_PORT/" $DAP_CFG || true +sed -i .old "s/{SERVER_ADDR}/$DAP_SERVER_ADDR/" $DAP_CFG || true +rm $DAP_CFG.old + +# Init dapcash-testnet +NET_NAME="dapcash-testnet" + +if [ "$DAP_DAPCASH_TESTNET_ENABLED"="true" ]; then + DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg" + DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl" + DAP_NET_CFG="" + if [ -e "$DAP_CFG_NET" ]; then + DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.new" + else + DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg" + fi + + cat $DAP_CFG_NET_TPL > $DAP_NET_CFG || true + sed -i .old "s/{NODE_TYPE}/$DAP_DAPCASH_TESTNET_ROLE/" $DAP_NET_CFG || true + rm $DAP_NET_CFG.old +fi + diff --git a/sources/main.c b/sources/main.c index cfee329..6136e06 100755 --- a/sources/main.c +++ b/sources/main.c @@ -159,7 +159,7 @@ int main( int argc, const char **argv ) #ifdef _WIN32 g_sys_dir_path = dap_strdup_printf("%s/%s", regGetUsrPath(), dap_get_appname()); #elif DAP_OS_MAC - g_sys_dir_path = dap_strdup_printf("/Applications/%s.app/Contents/Resources", dap_get_appname()); + g_sys_dir_path = dap_strdup_printf("/Applications/DapCash.app/Contents/Resources"); #elif DAP_OS_ANDROID g_sys_dir_path = dap_strdup_printf("/storage/emulated/0/opt/%s",dap_get_appname()); #elif DAP_OS_UNIX @@ -177,7 +177,6 @@ int main( int argc, const char **argv ) DAP_DELETE(l_log_dir); DAP_DELETE(l_log_file); } - { char l_config_dir[MAX_PATH] = {'\0'}; dap_sprintf(l_config_dir, "%s/etc", g_sys_dir_path); -- GitLab