install.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. # Run Django migrations and other commands
  73. python manage.py makemigrations dbsynce tickets webservice_running landing user
  74. python manage.py migrate
  75. python manage.py collectstatic -l --no-input
  76. # Seeding data
  77. python manage.py create_metaservice_default_data
  78. if (($GENERATE_TEST_USERS)); then
  79. python manage.py create_metaservice_test_users
  80. fi
  81. echo_warning "Recreating sharix_open.service"
  82. \cp conf/sharix_open.service.example conf/sharix_open.service
  83. sed -i "s|WORKING_DIRECTORY|$(pwd)|g" conf/sharix_open.service
  84. echo_success "Recreated sharix_open.service"
  85. echo_warning "Copying sharix_open.service to /etc/systemd/system/ folder"
  86. \cp conf/sharix_open.service /etc/systemd/system/
  87. echo_success "Copied sharix_open.service to /etc/systemd/system/ folder"
  88. echo_warning "Reloading systemd daemon"
  89. systemctl daemon-reload
  90. echo_success "Reloaded systemd daemon"
  91. # Checking for webservice_running/handlers/.env
  92. if [ -f webservice_running/handlers/.env ]; then
  93. echo "env file for handlers already exists. "
  94. else
  95. echo_warning "Creating env file for handlers."
  96. cp webservice_running/handlers/.env.example webservice_running/handlers/.env
  97. echo_success "Created env file for handlers."
  98. fi