Update setup.sh

This commit is contained in:
tripathyr 2024-11-27 10:09:01 +05:30 committed by GitHub
parent 71d7bf07b4
commit 56bd2af9cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,7 @@
#!/bin/bash
# =====================
# Setup Script for PyFLO, MySQL, and FLO Token Tracking
# Setup Script for PyFLO, MySQL, Virtual Environment, and FLO Token Tracking
# =====================
# Exit on any error
@ -13,34 +13,71 @@ sudo apt update
# Step 2: Install System Dependencies
echo "Installing system dependencies..."
sudo apt install -y build-essential libssl-dev pkg-config python3.7-dev python3-setuptools git
sudo apt install -y build-essential libssl-dev pkg-config python3-setuptools git
# Inform the user
echo "System dependencies installed successfully."
# Step 3: Install MySQL
echo "Installing MySQL server, client, and development libraries..."
sudo apt install -y mysql-server mysql-client libmysqlclient-dev
# Step 3: Check and Install Python 3.7
echo "Checking for Python 3.7..."
if ! python3.7 --version &>/dev/null; then
echo "Python 3.7 not found. Installing Python 3.7..."
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install -y python3.7 python3.7-venv
echo "Python 3.7 installed successfully."
else
echo "Python 3.7 is already installed."
fi
# Start and enable MySQL service
sudo systemctl start mysql
sudo systemctl enable mysql
# Step 4: Set Up Virtual Environment Using Python 3.7
VENV_NAME="myenv"
echo "Setting up virtual environment using Python 3.7..."
/usr/bin/python3.7 -m venv $VENV_NAME
echo "Virtual environment '$VENV_NAME' created successfully."
# Activate the virtual environment
source $VENV_NAME/bin/activate
# Inform the user
echo "MySQL server and client installed successfully. MySQL service is running."
echo "Virtual environment activated. Using Python version:"
python --version
# Step 4: Configure MySQL Default User and Privileges
# Step 5: Check and Install MySQL
echo "Checking if MySQL is installed..."
if ! dpkg -l | grep -q mysql-server; then
echo "MySQL is not installed. Installing MySQL server, client, and development libraries..."
sudo apt install -y mysql-server mysql-client libmysqlclient-dev
echo "MySQL installed successfully."
else
echo "MySQL is already installed. Skipping installation."
fi
# Step 6: Check and Start MySQL Service
echo "Checking if MySQL service is running..."
if systemctl is-active --quiet mysql; then
echo "MySQL is already running."
else
echo "MySQL is not running. Starting MySQL..."
sudo systemctl start mysql
echo "MySQL service started."
fi
# Enable MySQL to start on boot
sudo systemctl enable mysql
# Step 7: Configure MySQL Default User and Privileges
echo "Configuring MySQL user and privileges..."
MYSQL_USER="FUfB6cwSsGDbQpmA7Qs8zQJxU3HpwCdnjT"
MYSQL_PASSWORD="RAcifrTM2V75ipy5MeLYaDU3UNcUXtrit933TGM5o7Yj2fs8XdP5"
sudo mysql -e "CREATE USER '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';"
sudo mysql -e "CREATE USER IF NOT EXISTS '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';"
sudo mysql -e "GRANT ALL PRIVILEGES ON rm_%_db.* TO '${MYSQL_USER}'@'localhost' WITH GRANT OPTION;"
sudo mysql -e "FLUSH PRIVILEGES;"
echo "MySQL user '${MYSQL_USER}' created and granted privileges on databases matching 'rm_%_db'."
# Step 5: Clone the PyFLO Repository
# Step 8: Clone the PyFLO Repository
if [ ! -d "pyflo" ]; then
echo "Cloning the PyFLO repository..."
git clone https://github.com/ranchimall/pyflo
@ -48,7 +85,7 @@ else
echo "PyFLO repository already exists. Skipping clone."
fi
# Step 6: Install Python Dependencies
# Step 9: Install Python Dependencies
echo "Installing Python dependencies..."
if [ ! -f "requirements.txt" ]; then
# Generate a requirements.txt file if missing
@ -68,14 +105,14 @@ pip install --upgrade pip
# Install Python packages
pip install --use-pep517 -r requirements.txt
# Step 7: Install PyFLO
# Step 10: Install PyFLO
echo "Installing PyFLO..."
sudo python3 pyflo/setup.py install
# Inform the user
echo "Python dependencies and PyFLO installed successfully."
# Step 8: Clone the FLO Token Tracking Repository
# Step 11: Clone the FLO Token Tracking Repository
if [ ! -d "flo-token-tracking" ]; then
echo "Cloning the FLO Token Tracking repository (mysql-migration branch)..."
git clone --branch mysql-migration https://github.com/ranchimall/flo-token-tracking
@ -83,15 +120,18 @@ else
echo "FLO Token Tracking repository already exists. Skipping clone."
fi
# Step 9: Navigate into the FLO Token Tracking Directory
# Step 12: Navigate into the FLO Token Tracking Directory
echo "Navigating into the FLO Token Tracking directory..."
cd flo-token-tracking
# Inform the user
echo "You are now in the FLO Token Tracking directory. Setup complete!"
# Step 13: Start the Python Application
echo "Starting the Python application 'tracktokens-smartcontracts.py'..."
python3.7 tracktokens-smartcontracts.py
# Final Instructions
echo "========================================================"
echo "Setup is complete. MySQL server is installed and running."
echo "Virtual environment '$VENV_NAME' is set up and active."
echo "MySQL user '${MYSQL_USER}' has been created with privileges on databases matching 'rm_%_db'."
echo "The Python application has been started."
echo "========================================================"