install.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. source bin/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. # Function to check if a repository exists and perform git pull or git clone
  30. update_repository() {
  31. local repo_url="$1"
  32. local repo_dir="$2"
  33. local repo_branch="$3"
  34. if [ -d "$repo_dir" ]; then
  35. # If the directory exists, then do a git pull
  36. echo_warning "Updating $repo_dir..."
  37. cd "$repo_dir" || exit
  38. git checkout $repo_branch
  39. git pull
  40. cd - || exit
  41. else
  42. # If the directory does not exist, then do a git clone
  43. echo_warning "Cloning $repo_url into $repo_dir..."
  44. git clone -b "$repo_branch" "$repo_url" "$repo_dir"
  45. fi
  46. }
  47. # Update repositories
  48. update_repository "$TICKETS" "tickets" "$TICKETS_BRANCH"
  49. update_repository "$BACKEND" "dbsynce" "$BACKEND_BRANCH"
  50. update_repository "$CONFIG" "conf" "$CONFIG_BRANCH"
  51. update_repository "$DESIGN_TEMPLATE" "design_template" "$DESIGN_TEMPLATE_BRANCH"
  52. update_repository "$WEBSERVICE_RUNNING" "webservice_running" "$WEBSERVICE_RUNNING_BRANCH"
  53. update_repository "$LANDING" "landing" "$LANDING_BRANCH"
  54. update_repository "$USER_MODEL" "user" "$USER_MODEL_BRANCH"
  55. git pull
  56. # Create a Python virtual environment and activate it
  57. python3 -m venv venv
  58. source venv/bin/activate
  59. # Upgrade pip and install requirements
  60. pip install --upgrade pip
  61. pip install -r requirements.txt
  62. # Checking for core/settings_vars.py
  63. if [ -f core/settings_vars.py ]; then
  64. echo "File settings_vars.py already exists"
  65. else
  66. cp core/_settings_vars.py core/settings_vars.py
  67. echo "File settings_vars.py was successfully created"
  68. echo "Write the connection settings for the PostgreSQL database."
  69. echo "Restart install.sh script after editing."
  70. exit
  71. fi
  72. # Checking for sharix_open.service
  73. if [ -f conf/sharix_open.service ]; then
  74. echo "File sharix_open.service already exists"
  75. else
  76. cp conf/sharix_open.service.example conf/sharix_open.service
  77. echo_success "File sharix_open.service was successfully created"
  78. echo "Write the settings for systemd service, if you want."
  79. echo_warning "To continue, restart the install.sh"
  80. exit
  81. fi
  82. # Run Django migrations and other commands
  83. python manage.py makemigrations dbsynce tickets webservice_running landing user
  84. python manage.py migrate
  85. python manage.py collectstatic -l --no-input
  86. # Seeding data
  87. python manage.py create_metaservice_default_data
  88. if (($GENERATE_TEST_USERS)); then
  89. python manage.py create_metaservice_test_users
  90. fi
  91. #cp conf/sharix_open.service /etc/systemd/system/