Setting up Flask project in /root/here_we_go...
Creating virtual environment...
Activating virtual environment...
Upgrading pip...
Requirement already satisfied: pip in ./venv/lib/python3.12/site-packages (24.0)
Collecting pip
  Using cached pip-24.2-py3-none-any.whl.metadata (3.6 kB)
Using cached pip-24.2-py3-none-any.whl (1.8 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 24.0
    Uninstalling pip-24.0:
      Successfully uninstalled pip-24.0
Successfully installed pip-24.2
Installing Flask...
Requirement already satisfied: Flask in ./venv/lib/python3.12/site-packages (3.0.3)
Requirement already satisfied: Werkzeug>=3.0.0 in ./venv/lib/python3.12/site-packages (from Flask) (3.0.4)
Requirement already satisfied: Jinja2>=3.1.2 in ./venv/lib/python3.12/site-packages (from Flask) (3.1.4)
Requirement already satisfied: itsdangerous>=2.1.2 in ./venv/lib/python3.12/site-packages (from Flask) (2.2.0)
Requirement already satisfied: click>=8.1.3 in ./venv/lib/python3.12/site-packages (from Flask) (8.1.7)
Requirement already satisfied: blinker>=1.6.2 in ./venv/lib/python3.12/site-packages (from Flask) (1.8.2)
Requirement already satisfied: MarkupSafe>=2.0 in ./venv/lib/python3.12/site-packages (from Jinja2>=3.1.2->Flask) (3.0.2)
Creating requirements.txt...
Creating project directories...
mkdir: cannot create directory ‘app’: Not a directory #!/bin/bash

# Exit immediately if a command exits with a non-zero status.
set -e

# Define the project base directory
PROJECT_DIR="/root/here_we_go"

# Check if the project directory exists
if [ ! -d "$PROJECT_DIR" ]; then
  echo "Error: Project directory $PROJECT_DIR does not exist."
  exit 1
fi

echo "Setting up Flask project in $PROJECT_DIR..."

# Navigate to the project directory
cd "$PROJECT_DIR"

# Create a Python virtual environment named 'venv'
echo "Creating virtual environment..."
python3 -m venv venv

# Activate the virtual environment
echo "Activating virtual environment..."
source venv/bin/activate

# Upgrade pip to the latest version
echo "Upgrading pip..."
pip install --upgrade pip

# Install Flask
echo "Installing Flask..."
pip install Flask

# Freeze the current packages into requirements.txt
echo "Creating requirements.txt..."
pip freeze > requirements.txt

# Create the directory structure
echo "Creating project directories..."
mkdir -p app/templates
mkdir -p app/static/css
mkdir -p app/static/js
mkdir -p app/static/images

# Create __init__.py
echo "Creating __init__.py..."
cat > app/__init__.py << EOF
from flask import Flask

app = Flask(__name__)

from app import routes
EOF

# Create routes.py
echo "Creating routes.py..."
cat > app/routes.py << EOF
from app import app
from flask import render_template

@app.route('/')
def home():
    return render_template('index.html')
EOF

# Create app.py
echo "Creating app.py..."
cat > app.py << EOF
from app import app

if __name__ == '__main__':
    app.run(debug=True)
EOF

# Create a basic index.html template
echo "Creating templates/index.html..."
cat > app/templates/index.html << EOF
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Flask App</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
  </head>
  <body>
    <h1>Welcome to Your Flask App!</h1>
    <p>This is a basic Flask application.</p>
    <script src="{{ url_for('static', filename='js/script.js') }}"></script>
  </body>
</html>
EOF

# Create a basic CSS file
echo "Creating static/css/style.css..."
cat > app/static/css/style.css << EOF
body {
    font-family: Arial, sans-serif;
    background-color: #f8f9fa;
    text-align: center;
    margin-top: 50px;
}

h1 {
    color: #343a40;
}
EOF

# Create a basic JavaScript file
echo "Creating static/js/script.js..."
cat > app/static/js/script.js << EOF
console.log('Flask app is running.');
EOF

# Optionally, create a static/images directory (currently empty)
echo "Creating static/images directory..."
mkdir -p app/static/images

# Deactivate the virtual environment
echo "Deactivating virtual environment..."
deactivate

echo "Flask project setup complete!"

echo "To activate the virtual environment, run:"
echo "source $PROJECT_DIR/venv/bin/activate"

echo "To run the Flask app, navigate to the project directory and execute:"
echo "python app.py"