From a6ae8d2aaf291f43a1061fae3ee77b36164e3dcc Mon Sep 17 00:00:00 2001 From: Christian Kessler Date: Tue, 13 Aug 2024 13:04:12 -0700 Subject: [PATCH] Update update_bootnodes.sh Signed-off-by: Christian Kessler --- update_bootnodes.sh | 95 ++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/update_bootnodes.sh b/update_bootnodes.sh index cd3aa6c3..3586a849 100644 --- a/update_bootnodes.sh +++ b/update_bootnodes.sh @@ -6,52 +6,36 @@ print_message() { echo "${MESSAGE}" } -# Function to install Python 3 and pip3 -install_python3() { - # Detect the operating system - OS=$(uname -s) - - if [ "$OS" == "Linux" ]; then - # Check if the system is using apt (Debian/Ubuntu) - if command -v apt-get &> /dev/null; then - sudo apt-get update - sudo apt-get install -y python3 python3-pip - # Check if the system is using yum (CentOS/RHEL) - elif command -v yum &> /dev/null; then - sudo yum install -y python3 python3-pip - else - echo "Unsupported Linux package manager. Please install Python 3 manually." - exit 1 - fi - elif [ "$OS" == "Darwin" ]; then - # macOS - if command -v brew &> /dev/null; then - brew install python3 - else - echo "Homebrew not found. Please install Homebrew and try again." - exit 1 - fi - else - echo "Unsupported OS. Please install Python 3 manually." - exit 1 +# Function to create and activate a virtual environment +create_and_activate_venv() { + VENV_DIR=".venv" + + # Check if the virtual environment already exists + if [ ! -d "$VENV_DIR" ]; then + echo "Creating virtual environment in ${VENV_DIR}..." + python3 -m venv "$VENV_DIR" fi - # Ensure Python 3 is usable in PATH - if ! command -v python3 &> /dev/null; then - echo "Python 3 installation failed or not found in PATH." - exit 1 - else - echo "Python 3 is successfully installed and available in PATH." - fi + # Activate the virtual environment + echo "Activating virtual environment..." + source "${VENV_DIR}/bin/activate" - # Install tqdm using pip3 - sudo -H pip3 install tqdm + # Upgrade pip within the virtual environment + pip install --upgrade pip +} - if ! python3 -m pip show tqdm &> /dev/null; then - echo "tqdm installation failed." - exit 1 - else +# Function to install tqdm using pip +install_tqdm() { + # Attempt to install tqdm + pip install tqdm + + # Check if tqdm was successfully installed + if python3 -m pip show tqdm &> /dev/null; then echo "tqdm is successfully installed." + return 0 + else + echo "tqdm installation failed. Falling back to ASCII progress bar." + return 1 fi } @@ -60,7 +44,22 @@ insert_bootnodes() { python3 <