diff --git a/mytoncore/functions.py b/mytoncore/functions.py index 1acec162..36059e0a 100755 --- a/mytoncore/functions.py +++ b/mytoncore/functions.py @@ -55,8 +55,8 @@ def Event(local, event_name): ValidatorDownEvent(local) elif event_name == "enable_ton_storage_provider": enable_ton_storage_provider_event(local) - elif event_name == "enable_liteserver_mode": - enable_liteserver_mode(local) + elif event_name.startswith("enable_mode"): + enable_mode(local, event_name) local.exit() # end define @@ -93,10 +93,12 @@ def enable_ton_storage_provider_event(local): #end define -def enable_liteserver_mode(local): +def enable_mode(local, event_name): ton = MyTonCore(local) - ton.disable_mode('validator') - ton.enable_mode('liteserver') + mode = event_name.split("_")[-1] + if mode == "liteserver": + ton.disable_mode('validator') + ton.enable_mode(mode) #end define diff --git a/mytoninstaller/settings.py b/mytoninstaller/settings.py index d04c5673..45d167bb 100644 --- a/mytoninstaller/settings.py +++ b/mytoninstaller/settings.py @@ -34,7 +34,11 @@ def FirstNodeSettings(local): validatorAppPath = local.buffer.validator_app_path globalConfigPath = local.buffer.global_config_path vconfig_path = local.buffer.vconfig_path - archive_ttl = 2592000 if local.buffer.mode == 'liteserver' else 86400 + + if os.getenv('ARCHIVE_TTL'): + archive_ttl = int(os.getenv('ARCHIVE_TTL')) + else: + archive_ttl = 2592000 if local.buffer.mode == 'liteserver' else 86400 # Проверить конфигурацию if os.path.isfile(vconfig_path): @@ -892,8 +896,8 @@ def CreateSymlinks(local): def EnableMode(local): args = ["python3", "-m", "mytoncore", "-e"] - if local.buffer.mode == 'liteserver': - args.append("enable_liteserver_mode") + if local.buffer.mode: + args.append("enable_mode_" + local.buffer.mode) else: return args = ["su", "-l", local.buffer.user, "-c", ' '.join(args)] diff --git a/scripts/install.py b/scripts/install.py new file mode 100644 index 00000000..da2a0078 --- /dev/null +++ b/scripts/install.py @@ -0,0 +1,98 @@ +import os +import subprocess +import inquirer + + +def run_cli(): + questions = [ + inquirer.List( + "mode", + message="Select installation mode (More on https://docs.ton.org/participate/nodes/node-types)", + choices=["validator", "liteserver"], + ), + inquirer.List( + "network", + message="Select network", + choices=["Mainnet", "Testnet", "Other"], + ), + inquirer.Text( + "config", + message="Provide network config uri", + ignore=lambda x: x["network"] != "Other", # do not ask this question if network is not 'Other' + validate=lambda _, x: x.startswith("http"), + ), + inquirer.Text( + "archive-ttl", + message="Send the number of seconds to keep the block data in the node database. Default is 2592000 (30 days)", + ignore=lambda x: x["mode"] != "liteserver", # do not ask this question if mode is not liteserver + validate=lambda _, x: not x or x.isdigit(), # must be empty string or a number + # default=2592000 + ), + inquirer.List( + "validator-mode", + message="Select mode for validator usage. You can skip and set up this later", + ignore=lambda x: x["mode"] != "validator", # do not ask this question if mode is not validator + choices=["Validator wallet", "Nominator pool", "Single pool", "Liquid Staking", "Skip"], + ), + inquirer.Confirm( + "dump", + message="Do you want to download blockchain's dump? " + "This reduces synchronization time but requires to download a large file", + ), + inquirer.Confirm( + "telemetry", + message="Are you agree with sending your node performance statistics?" + ) + ] + + answers = inquirer.prompt(questions) + + return answers + + +def parse_args(answers: dict): + mode = answers["mode"] + network = answers["network"].lower() + config = answers["config"] + archive_ttl = answers["archive-ttl"] + validator_mode = answers["validator-mode"] + dump = answers["dump"] + telemetry = answers["telemetry"] + + res = f' -n {network}' + + if network not in ('mainnet', 'testnet'): + res += f' -c {config}' + + if archive_ttl: + os.putenv('ARCHIVE_TTL', archive_ttl) # set env variable + + if validator_mode and validator_mode not in ('Skip', 'Validator wallet'): + if validator_mode == 'Nominator pool': + validator_mode = 'nominator-pool' + elif validator_mode == 'Single pool': + validator_mode = 'single-pool' + elif validator_mode == 'Liquid Staking': + validator_mode = 'liquid-staking' + res += f' -m {validator_mode}' + else: + res += f' -m {mode}' + + if dump: + res += ' -d' + if not telemetry: + res += ' -t' + + return res + + +def main(): + answers = run_cli() + command = parse_args(answers) + # subprocess.run('bash scripts/install.sh ' + command, shell=True) + print('bash install.sh ' + command) + subprocess.run(['bash', 'install.sh'] + command.split()) + + +if __name__ == '__main__': + main() diff --git a/scripts/install.sh b/scripts/install.sh index 5975351b..5cbb4b1a 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -67,6 +67,16 @@ while getopts ":c:tida:r:b:m:n:v:h" flag; do esac done + +if (( $# == 0 )); then # no arguments + echo "Running cli installer" + wget https://raw.githubusercontent.com/ton-blockchain/mytonctrl/master/scripts/install.py + pip3 install inquirer + python3 install.py +# python3 scripts/install.py + exit +fi + # Set config based on network argument if [ "${network}" = "testnet" ]; then config="https://ton-blockchain.github.io/testnet-global.config.json" @@ -81,7 +91,7 @@ cpus=$(lscpu | grep "CPU(s)" | head -n 1 | awk '{print $2}') memory=$(cat /proc/meminfo | grep MemTotal | awk '{print $2}') echo "This machine has ${cpus} CPUs and ${memory}KB of Memory" -if [ "$ignore" = false ] && ([ "${cpus}" -lt "${cpu_required}" ] || [ "${memory}" -lt "${mem_required}"]); then +if [ "$ignore" = false ] && ([ "${cpus}" -lt "${cpu_required}" ] || [ "${memory}" -lt "${mem_required}" ]); then echo "Insufficient resources. Requires a minimum of "${cpu_required}" processors and "${mem_required}" RAM." exit 1 fi @@ -128,7 +138,7 @@ echo -e "${COLOR}[4/5]${ENDC} Running mytoninstaller" parent_name=$(ps -p $PPID -o comm=) user=$(whoami) -if [ "$parent_name" = "sudo" ] || [ "$parent_name" = "su" ]; then +if [ "$parent_name" = "sudo" ] || [ "$parent_name" = "su" ] || [ "$parent_name" = "python3" ]; then user=$(logname) fi echo "User: $user"