|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import inquirer |
| 4 | + |
| 5 | + |
| 6 | +def run_cli(): |
| 7 | + questions = [ |
| 8 | + inquirer.List( |
| 9 | + "mode", |
| 10 | + message="Select installation mode (More on https://docs.ton.org/participate/nodes/node-types)", |
| 11 | + choices=["validator", "liteserver"], |
| 12 | + ), |
| 13 | + inquirer.List( |
| 14 | + "network", |
| 15 | + message="Select network", |
| 16 | + choices=["Mainnet", "Testnet", "Other"], |
| 17 | + ), |
| 18 | + inquirer.Text( |
| 19 | + "config", |
| 20 | + message="Provide network config uri", |
| 21 | + ignore=lambda x: x["network"] != "Other", # do not ask this question if network is not 'Other' |
| 22 | + validate=lambda _, x: x.startswith("http"), |
| 23 | + ), |
| 24 | + inquirer.Text( |
| 25 | + "archive-ttl", |
| 26 | + message="Send the number of seconds to keep the block data in the node database. Default is 2592000 (30 days)", |
| 27 | + ignore=lambda x: x["mode"] != "liteserver", # do not ask this question if mode is not liteserver |
| 28 | + validate=lambda _, x: not x or x.isdigit(), # must be empty string or a number |
| 29 | + # default=2592000 |
| 30 | + ), |
| 31 | + inquirer.List( |
| 32 | + "validator-mode", |
| 33 | + message="Select mode for validator usage. You can skip and set up this later", |
| 34 | + ignore=lambda x: x["mode"] != "validator", # do not ask this question if mode is not validator |
| 35 | + choices=["Validator wallet", "Nominator pool", "Single pool", "Liquid Staking", "Skip"], |
| 36 | + ), |
| 37 | + inquirer.Confirm( |
| 38 | + "dump", |
| 39 | + message="Do you want to download blockchain's dump? " |
| 40 | + "This reduces synchronization time but requires to download a large file", |
| 41 | + ), |
| 42 | + inquirer.Confirm( |
| 43 | + "telemetry", |
| 44 | + message="Are you agree with sending your node performance statistics?" |
| 45 | + ) |
| 46 | + ] |
| 47 | + |
| 48 | + answers = inquirer.prompt(questions) |
| 49 | + |
| 50 | + return answers |
| 51 | + |
| 52 | + |
| 53 | +def parse_args(answers: dict): |
| 54 | + mode = answers["mode"] |
| 55 | + network = answers["network"].lower() |
| 56 | + config = answers["config"] |
| 57 | + archive_ttl = answers["archive-ttl"] |
| 58 | + validator_mode = answers["validator-mode"] |
| 59 | + dump = answers["dump"] |
| 60 | + telemetry = answers["telemetry"] |
| 61 | + |
| 62 | + res = f' -n {network}' |
| 63 | + |
| 64 | + if network not in ('mainnet', 'testnet'): |
| 65 | + res += f' -c {config}' |
| 66 | + |
| 67 | + if archive_ttl: |
| 68 | + os.putenv('ARCHIVE_TTL', archive_ttl) # set env variable |
| 69 | + |
| 70 | + if validator_mode and validator_mode not in ('Skip', 'Validator wallet'): |
| 71 | + if validator_mode == 'Nominator pool': |
| 72 | + validator_mode = 'nominator-pool' |
| 73 | + elif validator_mode == 'Single pool': |
| 74 | + validator_mode = 'single-pool' |
| 75 | + elif validator_mode == 'Liquid Staking': |
| 76 | + validator_mode = 'liquid-staking' |
| 77 | + res += f' -m {validator_mode}' |
| 78 | + else: |
| 79 | + res += f' -m {mode}' |
| 80 | + |
| 81 | + if dump: |
| 82 | + res += ' -d' |
| 83 | + if not telemetry: |
| 84 | + res += ' -t' |
| 85 | + |
| 86 | + return res |
| 87 | + |
| 88 | + |
| 89 | +def main(): |
| 90 | + answers = run_cli() |
| 91 | + command = parse_args(answers) |
| 92 | + # subprocess.run('bash scripts/install.sh ' + command, shell=True) |
| 93 | + print('bash install.sh ' + command) |
| 94 | + subprocess.run(['bash', 'install.sh'] + command.split()) |
| 95 | + |
| 96 | + |
| 97 | +if __name__ == '__main__': |
| 98 | + main() |
0 commit comments