From ba79e46afcd6ef95c65e5b4775acbb3a715d33f6 Mon Sep 17 00:00:00 2001 From: Wasif Iqbal Date: Thu, 18 Jul 2024 15:43:27 -0500 Subject: [PATCH] fix: ack script (#2198) ## Why is this change needed? - fix: remove parentheses for prompt, which causes changes to occur in sub shell and are not persisted to the environment file ## Merge Checklist - [x] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard - [x] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore) --- scripts/hubble.sh | 134 +++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 68 deletions(-) diff --git a/scripts/hubble.sh b/scripts/hubble.sh index 5011cf52b9..81bddf422d 100755 --- a/scripts/hubble.sh +++ b/scripts/hubble.sh @@ -122,83 +122,81 @@ fetch_latest_docker_compose_and_dashboard() { # Prompt for hub operator agreement prompt_for_hub_operator_agreement() { - ( - env_file=".env" - - update_env_file() { - key="AGREE_NO_REWARDS_FOR_ME" - value="true" - temp_file="${env_file}.tmp" - - if [ -f "$env_file" ]; then - # File exists, update or append - updated=0 - while IFS= read -r line || [ -n "$line" ]; do - if [ "${line%%=*}" = "$key" ]; then - echo "$key=$value" >>"$temp_file" - updated=1 - else - echo "$line" >>"$temp_file" - fi - done <"$env_file" - - if [ $updated -eq 0 ]; then + env_file=".env" + + update_env_file() { + key="AGREE_NO_REWARDS_FOR_ME" + value="true" + temp_file="${env_file}.tmp" + + if [ -f "$env_file" ]; then + # File exists, update or append + updated=0 + while IFS= read -r line || [ -n "$line" ]; do + if [ "${line%%=*}" = "$key" ]; then echo "$key=$value" >>"$temp_file" + updated=1 + else + echo "$line" >>"$temp_file" fi + done <"$env_file" - mv "$temp_file" "$env_file" - else - # File doesn't exist, create it - echo "$key=$value" >"$env_file" + if [ $updated -eq 0 ]; then + echo "$key=$value" >>"$temp_file" fi - } - - prompt_agreement() { - tried=0 - while true; do - printf "⚠️ IMPORTANT: You will NOT get any rewards for running this hub\n" - printf "> Please type \"Yes\" to continue: " - read -r response - case $(printf "%s" "$response" | tr '[:upper:]' '[:lower:]') in - yes | y) - printf "✅ You have agreed to the terms of service. Proceeding...\n" - update_env_file - return 0 - ;; - *) - tried=$((tried + 1)) - if [ $tried -gt 10 ]; then - printf "❌ You have not agreed to the terms of service. Please run script again manually to agree and continue.\n" - exit 1 - fi - printf "[i] Incorrect input. Please try again.\n" - ;; - esac - done - } - - if grep -q "AGREE_NO_REWARDS_FOR_ME=true" "$env_file"; then - printf "✅ You have agreed to the terms of service. Proceeding...\n" - return 0 + + mv "$temp_file" "$env_file" else - # Check if stdin is a terminal - if [ -t 0 ]; then - prompt_agreement - return $? - fi + # File doesn't exist, create it + echo "$key=$value" >"$env_file" + fi + } - # If we've reached this point, shut down existing services since agreement is required + prompt_agreement() { + tried=0 + while true; do + printf "⚠️ IMPORTANT: You will NOT get any rewards for running this hub\n" + printf "> Please type \"Yes\" to continue: " + read -r response + case $(printf "%s" "$response" | tr '[:upper:]' '[:lower:]') in + yes | y) + printf "✅ You have agreed to the terms of service. Proceeding...\n" + update_env_file + return 0 + ;; + *) + tried=$((tried + 1)) + if [ $tried -gt 10 ]; then + printf "❌ You have not agreed to the terms of service. Please run script again manually to agree and continue.\n" + return 1 + fi + printf "[i] Incorrect input. Please try again.\n" + ;; + esac + done + } - # Setup the docker-compose command - set_compose_command + if grep -q "AGREE_NO_REWARDS_FOR_ME=true" "$env_file"; then + printf "✅ You have agreed to the terms of service. Proceeding...\n" + return 0 + else + # Check if stdin is a terminal + if [ -t 0 ]; then + prompt_agreement + return $? + fi - # Run docker compose down - $COMPOSE_CMD down - printf "❌ You have not agreed to the terms of service. Please run script again manually to agree and continue.\n" + # If we've reached this point, shut down existing services since agreement is required - return 1 - fi - ) + # Setup the docker-compose command + set_compose_command + + # Run docker compose down + $COMPOSE_CMD down + printf "❌ You have not agreed to the terms of service. Please run script again manually to agree and continue.\n" + + return 1 + fi } validate_and_store() {