fix_manage_services.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import re
  2. import os
  3. file_path = "manage_services.sh"
  4. with open(file_path, "r", encoding="utf-8", errors="replace") as f:
  5. content = f.read()
  6. # Replace encoding issues in header
  7. content = content.replace("Lange Franois", "Francois Lange")
  8. content = content.replace("Lange FranA ois", "Francois Lange")
  9. # 1. Update COMPOSE_FILE logic
  10. old_compose = 'COMPOSE_FILE="docker-compose.yml"'
  11. new_compose = """COMPOSE_FILE="docker-compose.yml"
  12. # Auto-detect WSL context and use port-shifted docker-compose-wsl.yml
  13. if [ -f "docker-compose-wsl.yml" ] && (grep -qi "microsoft" /proc/sys/kernel/osrelease 2>/dev/null || grep -qi "wsl" /proc/sys/kernel/osrelease 2>/dev/null); then
  14. COMPOSE_FILE="docker-compose-wsl.yml"
  15. fi"""
  16. content = content.replace(old_compose, new_compose)
  17. # 2. Update mysqladmin ping readiness check
  18. old_ping = """ # Wait for MySQL to become fully ready and accept connections
  19. log_info "Waiting for MySQL database socket to be available..."
  20. until docker compose -f "$COMPOSE_FILE" exec mysql mysqladmin ping -h"localhost" -u"root" -p"your_db_password_here" --silent; do
  21. sleep 2
  22. echo -n "."
  23. done"""
  24. new_ping = """ # Wait for MySQL to become fully ready and accept connections
  25. log_info "Waiting for MySQL database socket to be available..."
  26. DB_ROOT_PASS="your_db_password_here"
  27. if [ -f "./.env" ]; then
  28. ENV_PASS=$(grep '^[ \\t]*MYSQL_ROOT_PASSWORD[ \\t]*=' .env | sed 's/^.*=//' | tr -d '\\r\\n ')
  29. if [ ! -z "$ENV_PASS" ]; then
  30. DB_ROOT_PASS="$ENV_PASS"
  31. fi
  32. fi
  33. until docker compose -f "$COMPOSE_FILE" exec mysql mysqladmin ping -h"localhost" -u"root" -p"$DB_ROOT_PASS" --silent; do
  34. sleep 2
  35. echo -n "."
  36. done"""
  37. content = content.replace(old_ping, new_ping)
  38. with open(file_path, "w", encoding="utf-8") as f:
  39. f.write(content)
  40. print("manage_services.sh successfully updated and encoding sanitized.")