1
0

install.sh 3.5 KB

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