install.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. source bin/utils/functions.sh
  3. if [ -f bin/install.cfg ]; then
  4. echo "File install.cfg already exists"
  5. else
  6. attempts=0
  7. max_attempts=3
  8. while [ $attempts -lt $max_attempts ]; do
  9. echo_error "File install.cfg does not exist."
  10. read -p "Do you want to create it? (y/n) [default: y]: " answer
  11. if [[ "$answer" == "y" || "$answer" == "Y" ]]; then
  12. cp bin/install.cfg.example bin/install.cfg
  13. echo_success "File install.cfg was successfully created"
  14. echo_warning "Restart install.sh script after editing install.cfg"
  15. exit 0
  16. elif [[ "$answer" == "n" || "$answer" == "N" ]]; then
  17. echo_error "Error: You need to create the file manually and then continue."
  18. echo "cp /bin/install.cfg.example to /bin/install.cfg with your settings."
  19. exit 1
  20. else
  21. attempts=$((attempts + 1))
  22. echo_error "Invalid input. Please enter 'y' or 'n'. Attempt $attempts of $max_attempts."
  23. fi
  24. done
  25. echo_error "Exceeded maximum attempts. Exiting."
  26. exit 1
  27. fi
  28. source bin/install.cfg
  29. # Update repositories
  30. update_repository "$TICKETS" "tickets" "$TICKETS_BRANCH"
  31. update_repository "$BACKEND" "dbsynce" "$BACKEND_BRANCH"
  32. update_repository "$CONFIG" "conf" "$CONFIG_BRANCH"
  33. update_repository "$DESIGN_TEMPLATE" "design_template" "$DESIGN_TEMPLATE_BRANCH"
  34. update_repository "$WEBSERVICE_RUNNING" "webservice_running" "$WEBSERVICE_RUNNING_BRANCH"
  35. update_repository "$LANDING" "landing" "$LANDING_BRANCH"
  36. update_repository "$USER_MODEL" "user" "$USER_MODEL_BRANCH"
  37. git pull
  38. # Create a Python virtual environment and activate it
  39. python3 -m venv venv
  40. source venv/bin/activate
  41. # Upgrade pip and install requirements
  42. pip install --upgrade pip
  43. pip install -r requirements.txt
  44. # Checking for .env
  45. if [ -f .env ]; then
  46. echo "File .env already exists"
  47. else
  48. cp .env.example .env
  49. echo_success "File .env was successfully created"
  50. echo_warning "Write the connection settings for the PostgreSQL database."
  51. echo_warning "Restart install.sh script after editing."
  52. exit
  53. fi
  54. # Run Django migrations and other commands
  55. python manage.py makemigrations dbsynce tickets webservice_running landing user
  56. python manage.py migrate
  57. python manage.py collectstatic -l --no-input
  58. # Seeding data
  59. python manage.py create_metaservice_default_data
  60. if (($GENERATE_TEST_USERS)); then
  61. python manage.py create_metaservice_test_users
  62. fi
  63. echo_warning "Recreating sharix_open.service"
  64. \cp conf/sharix_open.service.example conf/sharix_open.service
  65. sed -i "s|WORKING_DIRECTORY|$(pwd)|g" conf/sharix_open.service
  66. echo_success "Recreated sharix_open.service"
  67. echo_warning "Copying sharix_open.service to /etc/systemd/system/ folder"
  68. \cp conf/sharix_open.service /etc/systemd/system/
  69. echo_success "Copied sharix_open.service to /etc/systemd/system/ folder"
  70. echo_warning "Reloading systemd daemon"
  71. systemctl daemon-reload
  72. echo_success "Reloaded systemd daemon"
  73. # Checking for webservice_running/handlers/.env
  74. if [ -f webservice_running/handlers/.env ]; then
  75. echo "env file for handlers already exists. "
  76. else
  77. echo_warning "Creating env file for handlers."
  78. cp webservice_running/handlers/.env.example webservice_running/handlers/.env
  79. echo_success "Created env file for handlers."
  80. fi
  81. echo_warning "Installation handlers"
  82. webservice_running/handlers/conf/bin/install.sh