From 6f23bb887cb30045c4a318ea89e0ced60e960b33 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Wed, 13 Sep 2023 04:25:30 +0800 Subject: [PATCH 1/9] (feat) modify start.sh command to use quickstart arguments references issue - https://github.com/hummingbot/hummingbot/issues/6564 --- start | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/start b/start index d048c725e6..e1cdc0707e 100755 --- a/start +++ b/start @@ -1,8 +1,8 @@ #!/bin/bash -# Check if bin/hummingbot.py exists -if [[ ! -f bin/hummingbot.py ]]; then - echo "Error: bin/hummingbot.py command not found. Make sure you are in the Hummingbot root directory" +# Check if bin/hummingbot_quickstart.py exists +if [[ ! -f bin/hummingbot_quickstart.py ]]; then + echo "Error: bin/hummingbot_quickstart.py command not found. Make sure you are in the Hummingbot root directory" exit 1 fi @@ -13,4 +13,4 @@ if [[ $CONDA_DEFAULT_ENV != "hummingbot" ]]; then fi # Run bin/hummingbot.py and append errors to logs/errors.log -./bin/hummingbot.py 2>> ./logs/errors.log \ No newline at end of file +./bin/hummingbot_quickstart.py 2>> ./logs/errors.log From 1bd55b1eb4c362e35b8e75138c2a391af67bfb24 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Tue, 19 Sep 2023 22:00:33 +0800 Subject: [PATCH 2/9] add argument parsing --- start | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/start b/start index e1cdc0707e..a802db51e2 100755 --- a/start +++ b/start @@ -1,5 +1,24 @@ #!/bin/bash +PASSWORD="" + +# Argument parsing +while getopts ":p:" opt; do + case $opt in + p) + PASSWORD="$OPTARG" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + # Check if bin/hummingbot_quickstart.py exists if [[ ! -f bin/hummingbot_quickstart.py ]]; then echo "Error: bin/hummingbot_quickstart.py command not found. Make sure you are in the Hummingbot root directory" @@ -12,5 +31,9 @@ if [[ $CONDA_DEFAULT_ENV != "hummingbot" ]]; then exit 1 fi -# Run bin/hummingbot.py and append errors to logs/errors.log -./bin/hummingbot_quickstart.py 2>> ./logs/errors.log +# If a password was provided, pass it to the Python script +if [[ ! -z "$PASSWORD" ]]; then + ./bin/hummingbot_quickstart.py -p "$PASSWORD" 2>> ./logs/errors.log +else + ./bin/hummingbot_quickstart.py 2>> ./logs/errors.log +fi From c52846e7d1b4629571734dfb9854731fe9c09d9c Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:45:23 +0800 Subject: [PATCH 3/9] added argument parsing for filename --- start | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/start b/start index a802db51e2..e40277a228 100755 --- a/start +++ b/start @@ -1,13 +1,17 @@ #!/bin/bash PASSWORD="" +FILENAME="" # Argument parsing -while getopts ":p:" opt; do +while getopts ":p:f:" opt; do case $opt in p) PASSWORD="$OPTARG" ;; + f) + FILENAME="$OPTARG" + ;; \?) echo "Invalid option: -$OPTARG" >&2 exit 1 @@ -31,9 +35,15 @@ if [[ $CONDA_DEFAULT_ENV != "hummingbot" ]]; then exit 1 fi -# If a password was provided, pass it to the Python script +# Build the command to run +CMD="./bin/hummingbot_quickstart.py" if [[ ! -z "$PASSWORD" ]]; then - ./bin/hummingbot_quickstart.py -p "$PASSWORD" 2>> ./logs/errors.log -else - ./bin/hummingbot_quickstart.py 2>> ./logs/errors.log + CMD="$CMD -p \"$PASSWORD\"" +fi +if [[ ! -z "$FILENAME" ]]; then + CMD="$CMD -f \"$FILENAME\"" fi + +# Execute the command +eval $CMD 2>> ./logs/errors.log + From 1e5ef1f52384706dde8d4ceec7bc3c7d63def347 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Wed, 20 Sep 2023 23:59:32 +0800 Subject: [PATCH 4/9] added exit codes - exit code 1 for invalid password - exit code 2 for invalid config file --- bin/hummingbot_quickstart.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/hummingbot_quickstart.py b/bin/hummingbot_quickstart.py index 9bb78f43f7..cd45d9a1f6 100755 --- a/bin/hummingbot_quickstart.py +++ b/bin/hummingbot_quickstart.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +import sys import argparse import asyncio import grp @@ -80,7 +81,11 @@ async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsMana if not Security.login(secrets_manager): logging.getLogger().error("Invalid password.") - return + sys.exit(1) # <-- Exit with code 1 for invalid password + + if config_file_name is not None and not os.path.exists(STRATEGIES_CONF_DIR_PATH / config_file_name): + logging.getLogger().error("Config file not found.") + sys.exit(2) # <-- Exit with code 2 for file not found await Security.wait_til_decryption_done() await create_yml_files_legacy() From 4e479defcbfcd52f401d16a39b1f809d976c4648 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:00:47 +0800 Subject: [PATCH 5/9] added error message for invalid pw / file --- start | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/start b/start index e40277a228..18a12669dd 100755 --- a/start +++ b/start @@ -46,4 +46,13 @@ fi # Execute the command eval $CMD 2>> ./logs/errors.log +EXIT_CODE=$? +# Check exit code for specific errors +if [[ $EXIT_CODE -eq 1 ]]; then + echo "Error: Incorrect password provided." + exit 1 +elif [[ $EXIT_CODE -eq 2 ]]; then + echo "Error: Invalid file or filename provided." + exit 2 +fi From b87b6cd2ac841bdc848a621df05947aaa627ee30 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Thu, 21 Sep 2023 00:30:36 +0800 Subject: [PATCH 6/9] minor changes --- bin/hummingbot_quickstart.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/hummingbot_quickstart.py b/bin/hummingbot_quickstart.py index cd45d9a1f6..53c8949317 100755 --- a/bin/hummingbot_quickstart.py +++ b/bin/hummingbot_quickstart.py @@ -79,13 +79,17 @@ async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsMana if args.auto_set_permissions is not None: autofix_permissions(args.auto_set_permissions) - if not Security.login(secrets_manager): - logging.getLogger().error("Invalid password.") - sys.exit(1) # <-- Exit with code 1 for invalid password - - if config_file_name is not None and not os.path.exists(STRATEGIES_CONF_DIR_PATH / config_file_name): - logging.getLogger().error("Config file not found.") - sys.exit(2) # <-- Exit with code 2 for file not found + # Check the file only if the -f parameter is passed + if config_file_name: + if not os.path.exists(STRATEGIES_CONF_DIR_PATH / config_file_name): + logging.getLogger().error("Config file not found.") + sys.exit(2) # <-- Exit with code 2 for file not found + + # Check the password only if the -p parameter is passed + if args.config_password: + if not Security.login(secrets_manager): + logging.getLogger().error("Invalid password.") + sys.exit(1) # <-- Exit with code 1 for invalid password await Security.wait_til_decryption_done() await create_yml_files_legacy() From d0ec1f816fb9ec91925ab284d3541f6a3937a40e Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Thu, 21 Sep 2023 04:01:03 +0800 Subject: [PATCH 7/9] add check if running within a docker container --- bin/hummingbot_quickstart.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bin/hummingbot_quickstart.py b/bin/hummingbot_quickstart.py index 53c8949317..9582d0c8e6 100755 --- a/bin/hummingbot_quickstart.py +++ b/bin/hummingbot_quickstart.py @@ -51,7 +51,6 @@ def __init__(self): help="Try to automatically set config / logs / data dir permissions, " "useful for Docker containers.") - def autofix_permissions(user_group_spec: str): uid, gid = [sub_str for sub_str in user_group_spec.split(':')] @@ -71,6 +70,11 @@ def autofix_permissions(user_group_spec: str): os.setgid(gid) os.setuid(uid) +def is_running_in_docker() -> bool: + """ + Check if the script is running inside a Docker container. + """ + return os.path.exists('/.dockerenv') async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsManager): config_file_name = args.config_file_name @@ -79,17 +83,19 @@ async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsMana if args.auto_set_permissions is not None: autofix_permissions(args.auto_set_permissions) - # Check the file only if the -f parameter is passed - if config_file_name: - if not os.path.exists(STRATEGIES_CONF_DIR_PATH / config_file_name): - logging.getLogger().error("Config file not found.") - sys.exit(2) # <-- Exit with code 2 for file not found - - # Check the password only if the -p parameter is passed - if args.config_password: - if not Security.login(secrets_manager): - logging.getLogger().error("Invalid password.") - sys.exit(1) # <-- Exit with code 1 for invalid password + # Only perform checks if not running inside Docker + if not is_running_in_docker(): + # Check the file only if the -f parameter is passed + if config_file_name: + if not os.path.exists(STRATEGIES_CONF_DIR_PATH / config_file_name): + logging.getLogger().error("Config file not found.") + sys.exit(2) # <-- Exit with code 2 for file not found + + # Check the password only if the -p parameter is passed + if args.config_password: + if not Security.login(secrets_manager): + logging.getLogger().error("Invalid password.") + sys.exit(1) # <-- Exit with code 1 for invalid password await Security.wait_til_decryption_done() await create_yml_files_legacy() From 053331386d21c15470918ff59a586f475c1a6be3 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Thu, 21 Sep 2023 05:59:56 +0800 Subject: [PATCH 8/9] revert changes to hummingbot_quickstart.py --- bin/hummingbot_quickstart.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/bin/hummingbot_quickstart.py b/bin/hummingbot_quickstart.py index 9582d0c8e6..9bb78f43f7 100755 --- a/bin/hummingbot_quickstart.py +++ b/bin/hummingbot_quickstart.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import sys import argparse import asyncio import grp @@ -51,6 +50,7 @@ def __init__(self): help="Try to automatically set config / logs / data dir permissions, " "useful for Docker containers.") + def autofix_permissions(user_group_spec: str): uid, gid = [sub_str for sub_str in user_group_spec.split(':')] @@ -70,11 +70,6 @@ def autofix_permissions(user_group_spec: str): os.setgid(gid) os.setuid(uid) -def is_running_in_docker() -> bool: - """ - Check if the script is running inside a Docker container. - """ - return os.path.exists('/.dockerenv') async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsManager): config_file_name = args.config_file_name @@ -83,19 +78,9 @@ async def quick_start(args: argparse.Namespace, secrets_manager: BaseSecretsMana if args.auto_set_permissions is not None: autofix_permissions(args.auto_set_permissions) - # Only perform checks if not running inside Docker - if not is_running_in_docker(): - # Check the file only if the -f parameter is passed - if config_file_name: - if not os.path.exists(STRATEGIES_CONF_DIR_PATH / config_file_name): - logging.getLogger().error("Config file not found.") - sys.exit(2) # <-- Exit with code 2 for file not found - - # Check the password only if the -p parameter is passed - if args.config_password: - if not Security.login(secrets_manager): - logging.getLogger().error("Invalid password.") - sys.exit(1) # <-- Exit with code 1 for invalid password + if not Security.login(secrets_manager): + logging.getLogger().error("Invalid password.") + return await Security.wait_til_decryption_done() await create_yml_files_legacy() From ef7e1e1545060d6548c0180ddff9ff73480b7f93 Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Thu, 21 Sep 2023 06:02:11 +0800 Subject: [PATCH 9/9] check error logs reverted change to using exit codes and instead start command will check the error logs and output the result in the terminal --- start | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/start b/start index 18a12669dd..1fba97b78d 100755 --- a/start +++ b/start @@ -44,15 +44,17 @@ if [[ ! -z "$FILENAME" ]]; then CMD="$CMD -f \"$FILENAME\"" fi +# Clear the errors.log file first before executing +> ./logs/errors.log + # Execute the command eval $CMD 2>> ./logs/errors.log -EXIT_CODE=$? -# Check exit code for specific errors -if [[ $EXIT_CODE -eq 1 ]]; then +# Check errors.log for specific errors +if grep -q "Invalid password" ./logs/errors.log; then echo "Error: Incorrect password provided." exit 1 -elif [[ $EXIT_CODE -eq 2 ]]; then +elif grep -q "FileNotFoundError" ./logs/errors.log; then echo "Error: Invalid file or filename provided." exit 2 fi