install.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. if [ -f bin/install.cfg ]; then
  3. echo "File install.cfg already exists"
  4. else
  5. attempts=0
  6. max_attempts=3
  7. while [ $attempts -lt $max_attempts ]; do
  8. read -p "File install.cfg does not exist. Do you want to create it? (y/n) [default: y]: " answer
  9. if [[ "$answer" == "y" || "$answer" == "Y" ]]; then
  10. cp bin/install.cfg.example bin/install.cfg
  11. echo "File install.cfg was successfully created"
  12. exit 0
  13. elif [[ "$answer" == "n" || "$answer" == "N" ]]; then
  14. echo "Error: You need to create the file manually and then continue."
  15. echo "cp /bin/install.cfg.example to /bin/install.cfg with your settings."
  16. exit 1
  17. else
  18. attempts=$((attempts + 1))
  19. echo "Invalid input. Please enter 'y' or 'n'. Attempt $attempts of $max_attempts."
  20. fi
  21. done
  22. echo "Exceeded maximum attempts. Exiting."
  23. exit 1
  24. fi
  25. source bin/install.cfg
  26. # Function to check if a repository exists and perform git pull or git clone
  27. update_repository() {
  28. local repo_url="$1"
  29. local repo_dir="$2"
  30. local repo_branch="$3"
  31. if [ -d "$repo_dir" ]; then
  32. # If the directory exists, then do a git pull
  33. echo "Updating $repo_dir..."
  34. cd "$repo_dir" || exit
  35. git pull
  36. cd - || exit
  37. else
  38. # If the directory does not exist, then do a git clone
  39. echo "Cloning $repo_url into $repo_dir..."
  40. git clone -b "$repo_branch" "$repo_url" "$repo_dir"
  41. fi
  42. }
  43. # Update repositories
  44. update_repository "$TICKETS" "tickets" "$TICKETS_BRANCH"
  45. update_repository "$BACKEND" "dbsynce" "$BACKEND_BRANCH"
  46. update_repository "$CONFIG" "conf" "$CONFIG_BRANCH"
  47. update_repository "$DESIGN_TEMPLATE" "design_template" "$DESIGN_TEMPLATE_BRANCH"
  48. update_repository "$WEBSERVICE_RUNNING" "webservice_running" "$WEBSERVICE_RUNNING_BRANCH"
  49. update_repository "$LANDING" "landing" "$LANDING_BRANCH"
  50. update_repository "$USER_MODEL" "user" "$USER_MODEL_BRANCH"
  51. git pull
  52. # Create a Python virtual environment and activate it
  53. python3 -m venv venv
  54. source venv/bin/activate
  55. # Upgrade pip and install requirements
  56. pip install --upgrade pip
  57. pip install -r requirements.txt
  58. # Checking for core/settings_vars.py
  59. if [ -f core/settings_vars.py ]; then
  60. echo "File settings_vars.py already exists"
  61. else
  62. cp core/_settings_vars.py core/settings_vars.py
  63. echo "File settings_vars.py was successfully created"
  64. echo "Write the connection settings for the PostgreSQL database."
  65. exit
  66. fi
  67. # Run Django migrations and other commands
  68. python manage.py makemigrations dbsynce tickets webservice_running landing user
  69. python manage.py migrate
  70. python manage.py collectstatic -l --no-input
  71. #cp conf/sharix_open.service /etc/systemd/system/